Scheduling the publication of posts, checking plugins for updates, creating backups - these are all typical examples of recurring tasks in WordPress. And this is where WP Cron comes into play. In this article, we'll explain what this means and when it makes sense to use server-sided Cron jobs instead.
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 it needs to perform on a regular basis. In this article, we'll look at what these tasks are, what problems they can cause, and how RAIDBOXES makes it super simple 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.
What is Cron?
Cron is a command for task scheduling that is built into Linux-based systems, e.g. Ubuntu, Debian, Mac OSX, as well as servers. For Windows, this feature is called "Task Scheduler".
Here are some docs on how to use the Cron feature in the various systems:
- Windows - Task Scheduler (uses a Graphic User Interface (GUI) for more usability)
- Mac - Launched jobs and Cron jobs (uses Terminal and requires some knowledge of bash scripting)
- Server - e.g. cPanel - (uses either an integrated GUI or Terminal)
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.
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.
And what does WP-Cron do?
The WordPress Cron file (wp-cron.php) contains the automated tasks your WordPress installation needs to run. This includes things like checking for WordPress or plugin updates 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 WordPress needs an HTTP/HTTPS request from your website to perform scheduled tasks. The Cron task is then placed in a queue to be executed.
You're probably correctly asking yourself:
Why does WP Cron only run when a user visits my website?!
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 every day to perform a task). In WP-Cron, on the other hand, you set intervals (for example 14:00 & interval X after). WP-Cron then runs the task at these intervals as long as a user has visited the page. For more information, see also: Understanding WP-Cron Schedulingfor helpful tips.
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
For websites with large numbers of visitors, WP-Cron can cause performance issues and can even leave your site vulnerable to a DDoS attack. Now, if the mention of a DDoS attack has got you gripping your mouse or coffee cup with fear, don't panic. As always, there's 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.
Setting up server-sided execution of wp-cron.php at RAIDBOXES
To make your work as easy as possible, the team at RAIDBOXES has built this feature directly into the RB Dashboard. You literally need five clicks to set up the server-side execution of WordPress Cron jobs! If you're a developer looking to save time, this is one of the easiest things to set up.
To enable server-side Cron jobs in your RAIDBOXES Dashboard, first go to the settings of your BOX and then click on "Cronjobs" in the sidebar.
Now you will see all the options for setting your Cron jobs.
Make the following configuration in the Cronjobs area:
- Switch off "Execute WP-Cron" (this prevents WP Cron from being triggered by website visitors).
- Enable "Server-side WP-Cron" (This will add a Cron task to the server to trigger wp-cron.php at the interval you specify).
That's all there is to it!
If you disable Execute WP-Cron and the option Server-side WP-Cron is also disabled, no more Cron jobs will be run on your site.
You don't need to contact your host, go into cPanel, or edit your wp-cron.php file manually. At RAIDBOXES, you only need a few clicks to monitor and manage your cron jobs – directly in the RB Dashboard. So there's no need to install an additional plugin to view your Cron jobs either.
If you'd like to make further changes, you can also specify the interval at which the wp-cron.php should be executed in the RAIDBOXES Dashboard.
Opinions are divided on the "best" interval for your Cron jobs. We recommend not going under five-minute intervals.
Edit your WordPress Cron jobs
If you don't want to install a plugin to edit your wp-cron.php file, you don't need to! At RAIDBOXES, you can easily manage your Cron jobs via the RB Dashboard as described above. Of course, you can also access your Cron jobs via SSH. Once you've connected to your account, you can edit wp-cron.php in the root directory of your WordPress website.
Do you want to make your workflow even more efficient with SSH? Take a look at our article "The Perfect WordPress Development Workflow with Git & SSH" now.
The most popular WordPress plugin for managing WP Cron jobs is "WP Crontrol”. Find and install the plugin directly in your WordPress under Plugins.
On WP Crontrol's plugin page on WordPress, you'll also find helpful information on how to use the plugin correctlyfor helpful tips.
Manual setup of the server to trigger WP Cron (not necessary at RAIDBOXES)
With a bit of set up, you can also configure your server to run wp-cron.php at certain intervals.
- Edit the wp-cron.php
- Disable your wp-cron.php file by adding the following code to the file:
Now wp-cron.php will no longer be triggered when a user visits your website.
- 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 run your website with cPanel and have access to your command line, check out the 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
Are you expecting a surge of traffic on your WordPress website, e.g. due to a marketing campaign? Then you need to prepare properly! Our Head of Development Matthias will show you which 13 measures you need to take for your site to handle high load.
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 managing your WP Cron jobs as easy and convenient as possible via the RAIDBOXES Dashboard. This fast and direct access allows you to optimize your development and management processes even further.
Do you have further questions about WP-Cron or our RB Dashboard? Then please leave us a comment! You want to be informed about new WordPress articles? Then follow us on Twitter, Facebook , or subscribe to our newsletter.