[et_pb_section fb_built=”1″ _builder_version=”3.20.1″][et_pb_row _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.20.1″]

Cron jobs are scheduled tasks that the system runs at predefined times or intervals. In WordPress, these tasks include publishing scheduled posts, checking for system updates, running scheduled backups, or anything date/time-related.

WordPress uses the wp-cron.php file to simulate a regular system cron job to handle these tasks.

We have put together some steps to disabling the WordPress WP-cron (wp-cron.php) and setting up a system cron instead for better website performance:

 

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section][et_pb_section fb_built=”1″ _builder_version=”3.20.1″][et_pb_row module_id=”performance” _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.20.1″]

Why WP-Cron causes performance issues

While dealing with alot of high-traffic websites at Cloud Matrix we’ve seen some performance issues caused by the built-in WordPress Cron handler. It is important to understand that WP-Cron is not a real cron job, it’s simply what WordPress has created to mimic what a system cron does.

WP-Cron does not run continuously, but by default, it will fire on each new page load. If your website has a large amount of traffic, or if it is being scanned by bots (which is pretty common), the built-in WordPress cron handler has the effect of drastically increasing the server load generated by your site by triggering the wp-cron.php file. If a site doesn’t have enough PHP workers, when a request comes in, WordPress will spawn the cron which then has to wait for the worker to complete before it is handled.

On the flip side of this, if your website doesn’t have a lot of traffic, schedules could be missed due to the fact that no pages have been loaded to trigger the tasks.

We recommend disabling the WP-Cron and use a system cron instead. This runs the cron on a pre-defined schedule and is even recommended in the official Plugin handbook.

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section][et_pb_section fb_built=”1″ _builder_version=”3.20.1″][et_pb_row module_id=”disable-wp-cron” _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.20.1″]

How to disable WP-Cron

To disable WP-Cron, add the following to your wp-config.php file, just before the line that says “That’s all, step editing! Happy blogging.” Note: This disables it from running on page load, not when you call it directly via wp-cron.php.

define('DISABLE_WP_CRON', true);

wp-config.php disabled wp-cron

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section][et_pb_section fb_built=”1″ _builder_version=”3.20.1″][et_pb_row module_id=”schedule-cron” _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.20.1″]

How to schedule a system Cron Job

You will then need to schedule wp-cron.php from your server. The great news is that if you’re a Cloud Matrix client, systems crons are already enabled and run every 15 minutes by default. If needed, you can increase the frequency by reaching out to our support team.

If you’re familiar with SSH, you can also follow our tutorial on how to manage server crons from the command line at Cloud Matrix. All of our hosting plans include SSH access.

If you’re not a Cloud Matrix client, we recommend checking out these resources to learn how to set up system crons:

 

  •  Properly Setting Up WordPress Cron Jobs
  • Using WP CLI to Run Cron Jobs on Multisite Networks

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.20.1″]

Create Cron Job in cPanel

cPanel allows you to create a system cron job easily and visually. Make sure you have already disabled the default WP-Cron in your wp-config.php file as outlined above first. If you forget to disable it, you will be adding additional load to your server.

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row module_id=”schedule-cron” _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.20.1″]

Step 1

Log in to cPanel.
Navigate to “Cron Jobs” under the “Advanced” section of your cPanel dashboard.

cPanel Dashboard Cron Jobs

[/et_pb_text][et_pb_text _builder_version=”3.20.1″]

Step 2

Under the Add New Cron Job section, you can choose from a number of different pre-defined schedules, such as twice per hour or once per week. Your hosting provider most likely has a limit on how often they allow cron jobs to be run.

Set this to “Once Per Fifteen Minutes”

Cron Job Common Settings

[/et_pb_text][et_pb_text _builder_version=”3.20.1″]

Step 3

Add the following command. Remember to replace [domain.com] with your domain name. This command might vary slightly based on how your hosting is configured. Then click on the “Add New Cron Job.” button.

wget -q -O - https://[domain.com]/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Add new cron job

The >/dev/null 2>&1part of the command above disables email notifications.

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section][et_pb_section fb_built=”1″ _builder_version=”3.20.1″][et_pb_row _builder_version=”3.20.1″][et_pb_column type=”4_4″ _builder_version=”3.20.1″ parallax=”off” parallax_method=”on”][et_pb_divider _builder_version=”3.20.1″][/et_pb_divider][et_pb_text _builder_version=”3.20.1″]

If you enjoyed this tutorial, then you’ll love our support. All Cloud Matrix’s Managed WP hosting plans include 24×7 support from skilled WordPress developers. Sign up for Managed WordPress hosting here.

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]