How to disable the WordPress CRON job and set it up in cPanel

Wordpress doesn’t have a built-in scheduler to run regular tasks, so to get around this it fires off a request to process wp-cron.php every time a visitor requests a page.

There are a couple of issues with this, firstly on busy sites this means this cron task will be running all the time - when it really doesn’t need to.

  • On a small website with a few pages and a few hundred visitors a day wp-cron.php isn't a problem, but imagine a larger website with maybe a 100 visitors an hour. If each visitor read your home page, and 2 others, that would mean that wp-cron.php is being called 300 times an hour, 7200 times a day and so on. Plus, on a busy/large website wp-cron.php might take a few minutes to run.
    Multiple copies of wp-cron.php can be started at once as well, because people don't wait in line to view your web pages! This means that more memory is needlessly consumed. It all snowballs into a horrible resource hog.
    We've seen some busy sites running multiple instances of wp-cron.php tasks consuming over 200Mb of virtual memory each! This will quickly exhaust your cPanel accounts' allowed memory allocation - that's if it hasn't exhausted your CPU allowance already. This may cause your website to fail to operate correctly.
  • Of course, if the site is well optimised and most of the page requests are being served from cache the request to process wp-cron.php may not happen as often as you’d like.

There is a solution, in both these cases - disable the Wordpress cron and setup a cPanel cron job on a schedule you control.

  1. Disable the WordPress cron task
    You’ll need to edit your sites wp-config.php file - this is normally found in the base directory of your Wordpress installation.  You can edit it using the cPanel File Manager.Once you’ve opened the file, find the section that looks like this:
    * @link https://codex.wordpress.org/Debugging_in_WordPress
    */
    define('WP_DEBUG', false);

    /* That's all, stop editing! Happy blogging. */

    Sometimes, often on development sites you’ll see define('WP_DEBUG', true);  which just means WordPress debugging is turned on.
    Add the following immediately after the WP_DEBUG line
    define('DISABLE_WP_CRON', true);

    So that section now looks like this
    * @link https://codex.wordpress.org/Debugging_in_WordPress
    */
    define('WP_DEBUG', false);
    define('DISABLE_WP_CRON', true);

    /* That's all, stop editing! Happy blogging. */

    Save the wp-config.php file.
  2. Now you’ll need to add the cron job in cPanel to replace this functionality.
    Before you do this, think about how often you really need this scheduled.
    As a rule if you only check your website once a day, then run wp-cron.php once a day. If you find that you are getting a lot of spam comments and Akismet is not keeping on top of it, then you may want to set it to every 6 hours or so.
    Even if you were constantly working on a very busy site you would probably only want things to be processed every 30 minutes at the most.
    The command for the cron job you'll be seeting up is:
    /usr/bin/wget -O /dev/null https://www.mydomain/wp-cron.php?doing_wp_cron
    We have a separate article on adding cPanel Cron Jobs and there's a copy of this command in that article.


How did we do?


© Krystal Hosting Ltd 2003–2019