Disable wp-chron.php in WordPress and set as a scheduled task

From the wp-cron.php file:

 * WP-Cron is triggered when the site receives a visit. In the scenario
 * where a site may not receive enough visits to execute scheduled tasks
 * in a timely manner, this file can be called directly or via a server
 * cron daemon for X number of times.

The short version is that wp-cron is a scheduler function that performs routine tasks such as checking for version updates of WordPress files, themes and plugins as well as maintenance tasks like identifying spam comments.

The main issue that needs to be addressed is that WP-cron.php is triggered by someone visiting the site. On the surface this seems a very straightforward way to cause a task to launch without requiring external dependencies (like setting up a cron job on the web server hosting WordPress, etc) but this method raises some problems

A problem with caching

If your site uses any type of caching (using memcached or redis or some other method), incoming requests will hit the caching layer before hitting the actual web service. In this case there is no page load happening on the server and therefore won’t trigger wp-cron.

A problem with low traffic sites

With a low traffic site, page loads happen so infrequently that wp-cron won’t run regularly. While this won’t necessarily affect performance of the actual site, WordPress updates or spam may not be identified in a timely manner

A problem with high traffic sites

With a high traffic site, the constant invoking of wp-cron by each page load adds to server load, effectively DDoS-ing your own site. In addition, two page requests could cause a race condition as multiple wp-cron jobs work to complete the same tasks.

Disable wp-cron

First we disable the auto-invoking of wp-cron by opening up wp-config.php and adding the following line:

define('DISABLE_WP_CRON', true);

Schedule wp-cron as a task

I like to rename the wp-cron.php file to something else so that it cannot readily be invoked by an external visitor who happens to know what wp-cron is and feels like adding more work to your server.

I then create a Scheduled Task on the web server (I’m running WordPress on IIS on Windows Server 2019) that calls the following:

php c:\<full path to wp-cron.php>\wp-cron.php

and is set to run every five minutes.

Other methods

Some other methods to invoke wp-cron are:

  1. Use a scheduled task to invoke a curl call to the web site on a regular basis (useful for low traffic site).
  2. Use a plugin. Check The list of WP Cron plugins here.
  3. Invoke wp-cron from the command line using WP-CLI.

Leave a Comment

Your email address will not be published. Required fields are marked *