BFS10

What is WP-Cron? How to disable it and replace it with your own system Cron?

wordpress

In this post, we’re going to take you through everything that you need to know about WP-Cron.

We’ll find out what WP-Cron is, how it works, and how you can view all the WP-Cron jobs on your WordPress website. We’ll also share some of the reasons why you might want to disable WP-Cron and replace it with your own time-based system Cron. Then, we’ll conclude by showing you exactly how to do that in cPanel.

Let’s get into it!

What is WP-Cron?

what is cron

WordPress uses WP-Cron to handle scheduled time-based tasks in WordPress. So, if you schedule a post in advance to publish next Wednesday at 8 pm, WP-Cron is responsible for making sure that the post actually goes live at that time. So, WP-Cron handles all such time-bound or time-sensitive tasks in your WordPress Dashboard.

WP-Cron is essentially what makes any time-sensitive task function on time. It’s named after the Cron scheduling system on Unix-like operating systems. You can run tasks automatically on a schedule that you set with this system-level Cron.

But, WP-Cron is separate and distinct from those tools. Interestingly enough, WP-Cron isn’t just for actions that you schedule either. Many WordPress plugins also rely on WP-Cron to schedule their own tasks to run. For example, WooCommerce has lots of backend processes that rely on WP-Cron to run.

How does the WP-Cron work?

WP-Cron relies on visits to your site to function. This leads to one of its biggest shortcomings. Every time you or someone else visits your WordPress site, WordPress runs wp-cron.php and checks for any scheduled tasks. WordPress then goes on to process the scheduled tasks, if any. But, if there are no visitors, there’s nothing to trigger those tasks. This means that those tasks won’t execute until there’s a visit.

How to view WP-Cron jobs?

You can see and manipulate all the tasks that WP-Cron handles on your WordPress site using a plugin. WP Crontrol is a really neat and free plugin that can help you view WP-Cron jobs.

Install and activate the WP Crontrol plugin from WordPress.org. Once it’s installed, go to Tools > Cron Events. Here, you’ll see all the scheduled tasks on your WordPress site and how often/when they run. You can also manually run them if needed.

In the Cron Schedules tab, you’ll see all the different time schedule intervals, and you can even create your own If you want to know where a schedule comes from, just hover over it and WP Crontrol will display the relevant information.

Lastly,you can also create your own Cron events from the Add Cron Event or Add PHP Cron Event tabs.

Reasons to disable WP-Cron

disable wp-cron

Not Always Reliable

WP-Cron requires visits to work. This is one of its biggest limitations. Moreover, these could be front-end visits from other users or your own visits while you’re working in the dashboard. Irrespective of everything, WP-Cron needs visits to function. Your scheduled tasks won’t run without visits.

A high-traffic site, most likely, won’t face this issue. This is because you’ll always have people landing on your site which will make WP-Cron run. But it can cause real problems for low-traffic sites.

Let’s understand with an example. Let’s say you schedule a post to go live at 3 PM, but your site doesn’t receive any visitors until 7 PM. That means the post won’t go live until 7 PM because that’s the first chance that WP Cron has to execute those tasks.

This limitation might not be a big deal for blog posts, but it’ll also affect all the other time-based tasks on your site like updates, backups, and more.

With a real system-based Cron, you can configure it to trigger tasks every X minutes like clockwork. Now, it’ll trigger tasks whether or not your site has visitors.<span= id=”performancecorn”> This is a more predictable and reliable way to handle time-bound or time-sensitive tasks.

Might hurt performance

The first limitation doesn’t really apply to a high-traffic site. If you get visitors all the time, WP-Cron will have plenty of chances to run and won’t miss any tasks.

But that leads to another potential problem, that is, performance. By default, wp-cron.php fires on every single page load, and it can be a drag on performance. WordPress tries to limit this by not sending additional requests more than once per 60-second period. But, if your site gets multiple simultaneous requests, it can still lead to multiple requests to wp-cron.php.

Moreover, it’s highly unlikely that your site has tasks that must run every 60 seconds. You can surely use a less frequent schedule, like every 15 minutes, and it’ll still be fine.

How to disable WP-Cron and replace it with your own system Cron

disable wp-cron

By disabling WP-Cron we do not mean that time-based tasks will stop functioning on your site. We mean that instead of relying on visits to trigger WP-Cron, you can use a more reliable time-based system.

With your own system Cron, you’ll also be able to set the frequency as per your needs. Running it every 15 minutes is a good starting point. But, if you’re on a budget hosting, you might want to go to every 30 minutes.

Once set to 15 minutes, your site will execute all of the time-based tasks every 15 minutes only. Irrespective of the number of visits you get, your tasks will still fire every 15 minutes.
There are two parts to disabling WP-Cron:

    • Disabling WP-Cron in your wp-config.php file.

 

  • Setting up your own system Cron to load wp-cron.php on the schedule that you set.

We recommend that you back up your site before going any further because you’ll be making changes to the wp-config.php file.

1. Disabling WP-Cron in your wp-config.php file

After creating a backup of your website, connect to your site via FTP or a cPanel File Manager.

Then, find and edit the wp-config.php file, which is usually in the root folder of your site.
Add the following code snippet above the line that says: /* That’s all, stop editing! Happy publishing. */:

define(‘DISABLE_WP_CRON’, true);

2. Set up a system Cron

After disabling WP-Cron, you need to set up your own system Cron to run wp-cron.php. If you don’t do this, none of your WordPress website’s time-based tasks will run.

The process to do this depends on your hosting, but we’ll show you how to do it in cPanel. You can reach out to your host’s support for help in case if you’re stuck.

First, look for the tool called Cron Jobs, or something similar and open it.

You’ll see an interface that not only lets you set up a schedule for your Cron job but also the command that you want to run. In cPanel, use the Common Settings drop-down to choose a schedule. In case if that’s not available, you’ll have to follow Cron syntax for setting up the schedule. If you’re following Cron syntax, use Crontab.guru to easily generate the needed syntax.

If you’re on a budget hosting, running it every 30 minutes is a good starting point. You can go more or less frequently depending on your needs. Usually, most sites don’t need to run it any more often than every 15 minutes.

After setting up your schedule, enter the following code in the Command section:

wget -q -O – http://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

(Replace https://yourdomain.com with the actual domain name of your website)

Now, click Add New Cron Job and you’re all set. You should see it appear in the Current Cron Jobs section. If needed, you can always edit or delete the cron job from that section.
We recommend installing WP Crontol to ensure that your scheduled tasks are working. WP Crontrol will highlight any task that is not able to run.

Final Words

WP-Cron controls time-based tasks on your WordPress site. But, the default way that it functions can be unreliable for low-traffic sites and cause performance issues for high-traffic sites. That’s why you should consider disabling the default WP-Cron and replace it with your own time-based system Cron.

Got any questions? Let us know in the comments below or write to us and we’ll get back to you!

23 thoughts on “What is WP-Cron? How to disable it and replace it with your own system Cron?

  1. I’m really impressed with your writing skills
    and also with the layout of your blog.
    Keep up the excellent quality writing, it is rare to see a great blog like this one today.

  2. Excellent post. I was checking constantly this blog and I am
    impressed! Very helpful information particularly the last part 🙂 I care for such information a lot.

    I was looking for this particular information for a very long time.

    Thank you and best of luck.

  3. I do not even know how I ended up here, but I thought this post was great. I do not know who you are but certainly you are going to a famous blogger if you are not already 😉 Cheers!

  4. Hello There. I found your weblog using google. That is a very smartly written article.I will be sure to bookmark it and return to read extra of your useful info. Thanks for the post. I will definitely comeback.

Leave a Reply

Review Details

×

    Get Free Audit Report