Disabling WordPress Faux Cron

The WordPress WP-Cron system is a decently okay faux cron system, but it has its problems, such as running on frontend requests and not running if no requests are coming through.

WP-Cron works by: on every page load, a list of scheduled tasks is checked to see what needs to be run. Any tasks scheduled to be run will be run during that page load. WP-Cron does not run constantly as the system cron does; it is only triggered on page load. Scheduling errors could occur if you schedule a task for 2:00PM and no page loads occur until 5:00PM.

From the WordPress Plugin Handbook

These are problems because:

  • A heavy cron event can cause severe slowdown on random frontend requests, hurting page speeds.
  • Not running without requests can be bad for sites that are infrequently updated and heavily cached.

The solution to this is to disable the built-in cron firing that’s done with pageviews, and use a system cron (or other service) to poll for cron events.

Disabling the cron firing is done by adding this to the wp-config.php file:

define( 'DISABLE_WP_CRON', true );Code language: JavaScript (javascript)

For this site specifically, I use the “Cron Jobs” system of DreamHost to run this WP-CLI command every 10 minutes:

wp cron event run --due-now --path=/path/to/derrick.blog/ --url=https://derrick.blog/Code language: JavaScript (javascript)

This forces the cron to run and check for ready jobs every 10 minutes.  It’s possible that some cron events might run later than they “should” but in practice, I’ve seen this running more cron jobs than if I relied on page loads.

Other Posts Not Worth Reading

Hey, You!

Like this kind of garbage? Subscribe for more! I post like once a month or so, unless I found something interesting to write about.


One response to “Disabling WordPress Faux Cron”

  1. […] hosting your WordPress website on DreamHost, and use their cron system to offload your WordPress faux-cron for better reliability, be careful of what version of PHP you have in your […]

Leave a Reply