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?

+ -
@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 http://example.com/wp-cron.php > /dev/null 2>&1

And disable the cron in wp-config.php:

define('DISABLE_WP_CRON', true);

+ -
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 ...

+ -
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 |

@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.

@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.

+ -
@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?

+ -
@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.
@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