1. Home
  2. WordPress
  3. How to Disable WP-Cron for High Performance WordPress

How to Disable WP-Cron for High Performance WordPress

WP-Cron is how WordPress handles scheduling time-based tasks in WordPress. Several WordPress core features, such as checking for updates and publishing scheduled post, utilize WP-Cron. The “Cron” part of the name comes from the cron time-based task scheduling system that is available on UNIX systems.

Performance Issues with WP-Cron (wp-cron.php)

It’s important to understand that WP-Cron is not a real cron job, it was created by WordPress as a way to mimic the job of a system cron. WP-Cron does not run continously and by default it will run only when a page is loaded, which on high-traffic websites can cause problems. On the other hand if a website has low traffic, schedules will be missed because no one has loaded a page.

The best approach is to disable WP-Cron and use the system cron instead.

Problems with High Traffic Websites

You might run into problems with WP-Cron if your WordPress website is high traffic. The main issues that usually come up are race conditions and long running processes.

  • Race condition: When more than one user visits your website and triggers WP-Cron to execute the same job.
  • Long running process: Any task that takes longer than the standard 60 seconds to run. It’s possible to adjust this limit with set_time_limit() PHP function. If this is set to something longer than the windows between jobs, then you end up with more than one copy of wp-cron.php executing.

Problems with Low Traffic Websites

Since WP-Cron will run everytime there is a page load, in the chance that your website get a page load every couple days, it means that your WordPress will only perform schedules as Updates and Publish Scheduled Posts every couple days or even later.

How to Disable WP-Cron

To disable WP-Cron add the following line into your wp-config.php. This disables WP-Cron from running on page load, not when you send a call to wp-cron.php.

define('DISABLE_WP_CRON',true);

In order to edit wp-config.php you have 2 options. 1) Edit using cPanel File Manager or SSH if you are comfortable with the command line.

Edit wp-config.php using cPanel File Manager

Step 1. Go to your cPanel and click File Manager in Files.

Step 2. Double click in the blue globe icon.

Step 3. Click wp-config-php line and then click Edit.

Step 4. You will be prompted with editing settings. Let’s use default with UFT-8. Click Edit.

Step 5. Copy the line (Control+C) define(‘DISABLE_WP_CRON’, true); and Paste (Control+V) after <?php in line 1 and before your define (‘DB_NAME’, ‘user_dbname’ );

Step 6. You have edit wp-config.php sucessfully. Now let’s Setup a New System Cron.

Edit wp-config.php using SSH

Step 1. Go to your cPanel and click Terminal in Advanced.

Step 2. Type ´cd public_html´ and return Enter.

Step 3. Type ´nano wp-config.php´ and return Enter.

Step 4. Perfect! Now you have access wp-config.php inside your Terminal session.

Step 5. Move your cursor with down arrow in your keyboard and position between these lines. Copy the line (Control+C) define(‘DISABLE_WP_CRON’, true); and right click with your mouse into the Terminal windows in order to Paste, after <?php in line 1 and before your define (‘DB_NAME’, ‘user_dbname’ );

Step 6. Press Control+X to Save and Exit the Editor. You will be prompted with the question to ‘Save modified butffer?‘ Type Y and return Enter.

Step 7. Editor will ask for confirmation to write changes into file wp-config.php with the prompt ‘File Name to Write: wp-config.php‘. Return Enter.

Step 8. We just finished adding the line to Disable WP-Cron. Now it’s safe to Exit Terminal. Type exit and return Enter.

How to Setup New System Cron

Setup New Cron Job using cPanel

Step 1. Go to your cPanel and click Cron Jobs in Advanced.

Step 2. Select ‘Once Per Day‘ if you have low updates on your website. For high website updates go with ‘Once Per Hour‘. In the Command field Paste the following command below and click Add New Cron Job.

/opt/cpanel/ea-php74/root/usr/bin/php -q “/home/USERNAME/public_html/wp-cron.php”

The command provided in this Article refer to PHP 7.4. Please confirm your cPanel PHP version and change as necessary.

Example
If you are using PHP 8.0, your command should look like this instead:
/opt/cpanel/ea-php80/root/usr/bin/php -q “/home/USERNAME/public_html/wp-cron.php”

Related Articles

Leave a Comment