Better handling of WP-CRON server load abuse

There are multiple reports on how wp-cron is a far from ideal solution because it runs every time a page is loaded, which is unnecessary in most scenarios (one scenario in which it would be necessary is when you use scheduled posts)

The common advice is to add define('DISABLE_WP_CRON', true); to wp-config.php then schedule a real cron job (if you have enough admin access to so).

But as of WP 3.3, there is WP_CRON_LOCK_TIMEOUT, which “defines a period of time in which only one cronjob will be fired“.

If you run hundreds of WP installs you would have to create (and delete, when that wp install is removed) a LOT of cron jobs, which can become a nuisance. Therefore, it seems that the best solution these days is setting define('WP_CRON_LOCK_TIMEOUT', 900); (if you want wp-cron to run every 900 seconds).

The question is: has anyone used WP_CRON_LOCK_TIMEOUT with this purpose yet? Is this its intended use?

1
1

This is the intended use of the WP_CRON_LOCK_TIMEOUT constant.

When WordPress is loaded, it checks to see if a cron job is running (if cron is locked). If cron is not locked, it will try to create a lock – if the lock timeout has not been reached, no lock can be acquired and cron is not run.

If no cron job is running, and the timeout has passed (meaning a lock can be created), then cron is run.

Leave a Comment