What is WP-Cron and when are "real" cron jobs useful for your WordPress website?

What is WP-Cron and when are "real" cron jobs useful for your WordPress website?

Scheduling the publication of posts in WordPress , checking Plugins for updates, creating backups - these are all typical examples of tasks that happen repeatedly. And this is where WP-Cron comes into play in WordPress . What this means and when server-side cron jobs make more sense, we explain in this post.

As you know, your computer is constantly performing countless calculations with ones and zeros at breakneck speed, all of which have a job to do. Many of these are tasks that need to be repeated over and over again, much like brushing your teeth. On that note, I have a question for you:

If you could automate brushing your teeth, would you?

Your WordPress website has automated maintenance tasks that it needs to perform regularly. In this article we'll look at what these tasks are, what problems they can cause and how Raidboxes makes it super easy for you to manage them.

Every time your local computer displays a popup message telling you an update has been found or an email has arrived in your inbox, it's most likely a cronjob that is working behind the scenes.

"*" indicates required fields

I would like to subscribe to the newsletter to be informed about new blog articles, ebooks, features and news about WordPress. I can withdraw my consent at any time. Please note our Privacy Policy.
This field is for validation and should not be changed.

What is Cron? 

Cron is a task scheduling command that is integrated in Linux-based systems - such as Ubuntu, Debian or even Mac OSX - and also on servers. Under Windows, the functionality is called "Task Scheduler".

Here are some docs on how to use the Cron feature in the various systems: 

What does Cron do anyway?

The purpose of Cron is to perform repetitive tasks, e.g. checking for available updates or sending and receiving emails. This is usually set up for you by default. But the more software you have installed on your computer, the more jobs are likely to be added. As an example, the screenshot below shows a Cron job in the Task Scheduler in Windows 10. 

Windows Cron

You're wondering how Cron works? It works by scheduling tasks based on the time of your device and can be set up by the minute, hour, day, week, month, and year. In Cron, you set a specific time for an action to be performed. 

What is WP-Cron?

WordPress Cron, also known as WP-Cron, is a PHP file that is usually located in the root directory of your WordPress installation. 

Wp Cron Location

And what does WP-Cron do?

The WordPress cron file (wp-cron.php) contains the automated tasks that your WordPress installation needs to perform. For example, things like checking for updates to Plugins and WordPress or publishing scheduled posts. For more information, see the documentation "What is WP-Cron" in the official WordPress Plugin Handbook. 

WP-Cron versus Cron

The main difference between WordPress cron and the cron scheduler is that wp-cron.php is only executed when a user visits your website and triggers a page load. This means that WordPress requires an HTTP/HTTPS request from your website to run scheduled tasks. The cron task is then queued to be executed. 

You're probably correctly asking yourself:

Why does WP Cron only run when a user visits my site! 

Well, many WordPress hosting providers only offer shared hosting, which usually means your host won't give you access to the cron command. If they did, you'd have access to the server commands and all data on the server would be potentially compromised. WordPress Cron is therefore the workaround for this problem.

The second difference is that when using Cron, you can set specific times (for example, 17:00 daily to run a task). In WP-Cron, on the other hand, you set intervals (for example, 14:00 & interval X after that). WP-Cron then executes the task at those intervals as long as a user has visited site . For more info, see also: Understanding WP-Cron Scheduling

WP-Cron and performance

WP-Cron is only triggered whenever a user visits your website and this can cause problems for both small and large websites. Let me explain why.

Small & geographically specific websites

The problem for smaller websites with little traffic is that the cron task isn't executed often enough. Say, for example, you have a site for a small tour guide company only operating in one city and you want your website to make a backup at 2:00 a.m. It's very unlikely a user from your target audience will visit your website at 2:00 am and trigger the Cron job. And if it's low season, you might not get any visitors for days at a time. 

Larger websites & global reach

However, for sites with a large number of users, WP-Cron can cause some performance issues and even make your site vulnerable to a DDoS attack. Well, if you probably just panicked and grabbed your mouse or coffee cup at the mention of a DDoS attack: don't worry too much, because there is a solution for everything.

What causes the problem?

The amount of traffic causes the problem. Traffic is a must for large websites and generates business, so limiting it is not the way to solve the issue. 

Remember: Every visit to the site causes WP-Cron to be triggered - and this puts a strain on your server because it requires resources to run.

Is there a better way?

Fortunately, the answer is yes. While we can't simply remove web traffic, open physical stores around the globe, or change the way WordPress is set up, we can change what makes WP-Cron run. 

Instead of running wp-cron.php based on site visits, we can set up a Cron task on the hosting server that runs WP Cron at certain intervals. Let me show you how to do this.

Configure the server-side execution of wp-cron.php at Raidboxes

To make your job as easy as possible, the team here at Raidboxes has built this feature right into the Raidboxes Dashboard. You literally need five clicks to set up the server-side execution of WordPress cronjobs! If you're a developer looking to save time, this is one of the easiest things to do.

To enable server-side cronjobs in your Raidboxes Dashboard , first go to the settings of your BOX and then click on "Cronjobs" in the sidebar.

raidboxes dashboard wp-cron

Now you will see all the options for setting your Cron jobs. 

Cron Jobs Raidboxes


Make the following configuration in the Cronjobs area:

  1. Turn off "Run WP-Cron" (this prevents WP-Cron from being triggered by website visitors).
  2. Turn on "Run WP-Cron server-side" (this adds a cron task to the server to trigger wp-cron.php at the interval you specify). 

That's all there is to it!

Caution

If you turn off Run WP-Cron and also the Run WP-Cron server-side option is disabled, no more cron jobs will run on your site .

For this customization, it is therefore not necessary to contact your host, go into the cPanel or manually edit your wp-cron.php file. With Raidboxes, you only need a few clicks and you can monitor and manage your cronjobs directly in the RB-Dashboard. This means you don't need to install an additional plugin to display your cronjobs.

If you want to make further configurations, you can also specify in Raidboxes Dashboard the interval at which wp-cron.php should be executed.

Cron Time

There is a lot of speculation about the "best" interval for your cronjobs. We usually recommend not going below 5 minutes. 

Edit your WordPress Cron jobs

Without Plugins

If you don't want to install pluginto edit your wp-cron.php file, that's no problem! At Raidboxes you can easily manage your cronjobs via the RB-Dashboard as described above. Of course, you can also access your cronjobs via an SSH connection. Once you have connected to your account, you can edit wp-cron.php in the root directory of your WordPress website.

If you want to know how to make your workflow even more efficient with SSH, it's best to check out our article "The Perfect WordPress Development Workflow with Git & SSH". 

With Plugins

Currently the most popular Plugin for managing WP cronjobs is "WP Crontrol". You can also search and install the Plugin directly in your WordPress at Plugins and install it. 

plugin Wp Control

On WP Crontrol's Plugin-site at WordPress .org you can also find helpful documentation on how to use the Plugin properly

Manually set up the server to trigger WP-Cron (not necessary with Raidboxes)

With a bit of set up, you can also configure your server to run wp-cron.php at certain intervals.

  1. Edit the wp-cron.php 

In wp-cron.php

  • Disable your wp-cron.php file by adding the following code to the file:
define('DISABLE_WP_CRON', 'true');

Now wp-cron.php will no longer be triggered when a user visits your website.

  1. Add a Cron job to your server

In your server environment

Depending on your hosting environment, one of the two options listed below may apply to your specific situation: 

  • If you're using a shared WordPress hosting service and you don't have access to the Linux commands yourself, contact your hosting provider and ask them to add a server-side Cron trigger for wp-cron.php.
  • Or, if you're running your site with cPanel and have access to your command line, check out the appropriate cPanel documentation

The WP-Cron file is quickly overlooked when building a WordPress website but it can lead to noticeable errors when your site starts to attract more visitors.

Prepare WordPress for traffic peaks

You expect a lot of traffic on your WordPress website, e.g. due to a marketing campaign? Then you need the right preparation! Our Head of Development Matthias shows you which 13 measures you can take to prepare your WordPress for high loads.

Conclusion

I hope this article helps you understand what the WordPress Cron function is and how it works. Used properly, it can help you automate important tasks reliably so you can focus on running your business.

Our goal is to make the management of your WP cronjobs via Raidboxes Dashboard as simple and convenient as possible. In this way, you can further optimise the development and management of your sitethrough this fast and direct access.

Do you have more questions about WP-Cron or our dashboard? Feel free to leave us a comment! You want to be informed about new posts on WordPress ? Then follow us on Twitter, Facebook or via our newsletter.

Did you like the article?

Your rating helps us improve our future content.

A Comment on "What is WP-Cron and when are "real" cron jobs useful for your WordPress website?"

  1. Ist der Eintrag DISABLE_WP_CRON tatsächlich – wie im Artikel beschrieben – in der wp-cron.php einzufügen? Ich hätte einen solchen define-Eintrag eher in der wp-config.php vermutet.
    Viele Grüße Stefan

Post a comment

Your email address will not be published. Required fields are marked with *.