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 probably isn't a problem, but imagine a larger website with maybe a 100 visitors an hour. If each visitor reads 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 the opposite could also be the case - 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);  instead, which just means WordPress debugging is turned on. You can safely continue to follow these instructions.
    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. However you may want to run the CRON job more frequently:
    • If you find that you are getting a lot of spam comments and Akismet is not keeping on top of it
    • If you schedule posts to be published at specific times
    • If you publish event details that start and finish at specific times
    • If you run an e-commerce site with stock level control
    • If you integrate with any other system that requires regular updates or syncs to/from your WordPress site.
    Once you've set this up it's important that you monitor it to ensure all your site's functionality continues to work as expected, in a timely manner. You can always return to the CRON job in cPanel and adjust it's schedule at any point.
    In any event we'd advise you run the CRON not any less frequently that once a day or any more frequently than every minute.
    The command for the cron job you'll be setting 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?


Powered by HelpDocs (opens in a new tab)
© Krystal Hosting Ltd 2002–