Email or username:

Password:

Forgot your password?
Johannes Ernst

Anybody know how wp-cron.php in #WordPress works, exactly? It can be invoked explicitly, and it a also runs implicitly at the end of other HTTP GET requests? Is that right?

And then, if there are 1000 things in the queue, what does it do? Are the queue entries all "deliver asap" or can I schedule things for the future?

10 comments
Ross Wintle

@j12t It’s not a queue. But yes, if 1000 things are scheduled to run they will all run.

It runs in the background though so doesn’t hold up requests, which is why it’s spawned at the end of other requests.

Because web requests have a limited execution time it’s better to turn off the regular HTTP-invoked cron and run WP-cron from a system cron.

Does that make sense? Too technical? Other questions?

Johannes Ernst

@ross My use case is non-standard :-) For FediTest.org, I'd like to deliver outgoing ActivityPub messages asap, so my tests don't take longer than necessary. I've attempted to invoke wp-cron.php manually but it's not sending immediately ... 15 sec wait often works, but not always.

Ross Wintle

@j12t Sounds like you want an actual queue rather then job scheduling.

Trouble is the only queuing solution I know runs off of wp-cron!

github.com/deliciousbrains/wp-

Do you know what cron event your sending is hooked onto?

Otto

@j12t @ross how long does it take to run the process? For one single message, say. Is it a large number of traffic? Running on multiple servers? Things like this all fall into play depending on how you want to use it.

I can probably help you out with understanding this if needed, email me some info about it: otto at wordpress.org

Otto

@j12t for 99.9% of uses, wp-cron is perfectly fine for most sites.

If your site is (really) high traffic or the job you want to run requires a specific timing, then maybe you should look at something else.

But again, for the normal reasons you want to use wp-cron, it works perfectly fine, by just leaving it alone.

If you describe your use case, then I can give you more information on the right way to do it, because yes, I know exactly how it works. However, explaining it is... convoluted.

Johannes Ernst

Lots of helpful people here @pluhmen @ross @otto42! Thanks all!!

My use case is non-standard :-) For FediTest.org, I'd like to deliver outgoing ActivityPub messages asap, so my tests don't take longer than necessary. I've attempted to invoke wp-cron.php manually but it's not sending immediately ... 15 times with 1 sec delay often works, but not always. As soon as I open any page in the browser, it goes through, however. It's the unpredictability that I'm trying to understand ...

Johannes Ernst

Ah, "wp cron event list" to the rescue! If I guess at what this says, it might only attempt to send updates to Fediverse followers once an hour! That is not quite what the doctor ordered for testing purposes ...

| activitypub_update_followers | 2024-10-15 22:57:27 | 58 minutes 35 seconds | 1 hour |
| activitypub_cleanup_followers | 2024-10-16 21:57:27 | 23 hours 58 minutes | 1 day |

Otto

@j12t well, there's your problem. 😀

It seems most likely that it's putting these requests into a queue which then gets handled by an hourly event. So manually calling wp-cron won't make it happen any faster.

Jaz (IFTAS)

@j12t The stock mode is cron is triggered by a visitor. So, no visitors, no cron. Or, heavily cached, maybe no cron. Once you get a visitor, cron is triggered and a 60-second lock put in place. It is possible during an overwhelm of traffic (cough fediverse previews cough) to call cron multiple times before that lock is in place.

Alternatively you can use curl

*/10 * * * * curl example.com/wp-cron.php > /dev/null 2>&1

And disable the cron in wp-config.php:

define('DISABLE_WP_CRON', true);

Go Up