How to disable the default WordPress Cron execution method, and execute as a Cron Job via cPanel instead

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. 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.

2. 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. */

3. Add the following immediately after the WP_DEBUG line 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. */

4. Save the wp-config.php file.

5. 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.

You will probably want to run the Cron more frequently than once a day, but probably not more frequent 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

For full instructions on creating a Cron Job in cPanel, please read this article

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to remove multiple posts with a single click in WordPress?

It is possible to remove multiple post in your WordPress dashboard. You can also remove selected...

How to remove your post in Wordpress?

You can remove your published or draft post in Wordpress.1. Login to your WordPress admin...

How to add a new category in WordPress?

1. Login to your WordPress admin dashboard.2. Under the dashboard menu, hover your mouse on Posts...

How to remove the Uncategorized category from WordPress?

You can not remove "Uncategorized" Category but you can rename it1. Login to your WordPress admin...

How to remove a category in WordPress?

If you want to remove WordPress category then follow this instruction:1. Login to your WordPress...

Powered by WHMCompleteSolution