What Do You Need To Know About The WordPress Cron?

In this article, we explain:

  • What is the WP Cron?
  • How does it work?
  • Why does it fail?
  • What issues do WP Cron errors cause?
  • How to fix the WP Cron

So, let's get started...

What is the WP Cron?

Cron is a UNIX command for scheduling jobs to be executed sometime in the future. It's normally used to schedule a job that is executed periodically.

WordPress uses a file called wp-cron.php as a virtual cron job, or scheduled task in order to automate things like

  • publishing scheduled posts
  • checking for plugin or theme updates
  • sending email notifications
  • backing up
  • WordPress automatic updates
  • ... and so on.

How does it work?

On every page load, WordPress checks if there is a need for WP Cron to run. If there is a need, then it tries to make a request over HTTP to the wp-cron.php file.

Calling this file helps keep the WP Cron running as a separate process in the background without delaying the page load time for the user. Once the WP Cron starts, it continues to run until all the required jobs are completed or until it reaches an execution time as set in the server configuration.

It's important to explain that, in its default configuration, WordPress does not use a real cron job for scheduling and other related tasks. Instead, whenever a page is loaded on a WordPress site, WordPress runs the wp-cron.php file. It basically asks "is it time to do anything yet?".

If there are any tasks scheduled at the time of page load they will be run. But, it must be noted here that WP Cron does not run constantly as the system cron does.

WP Cron will only be triggered on page load - i.e. when someone visits a page on your site. This means that, for example, if you have a task scheduled for 4:00 PM but do not have any visitors until 10:00 PM your task will not run until then.

Note: Sometimes you may see URLs with ?doing_wp_cron= followed by a string of numbers.

For example:

https://example.com/what-is-wp-cron-article?doing_wp_cron=123456.874251298799871371475

This happens because, in order to do some background processing (like publishing scheduled posts), WordPress redirects you to the URL with ?doing_wp_cron appended.

Read more about this here.

Why does it fail?

So, when someone lands on any page on your WordPress site, the  wp-cron.php file could fire up and check whether it needs to send anything

On many WordPress hosts, this will run as intended. But, some hosts disable this functionality from running because it means that large visitor numbers can fire the virtual cron jobs a lot of times, using up the resources on your server. It’s also a potential security vulnerability.

Another reason is that some plugins and themes can cause fatal errors during cron processing (as they may not have been tested correctly) and this will break the running of the cron process.

Hint: While it's not conclusive and serves only really as a pointer in the case of major issues, on the Security Dashboard for Shield there's an entry under the Tools > Debug Info > Recent Events Log section to show the last time the simple test cron ran:

That would tell you whether or not your crons are, in general, working. It doesn’t mean that all your crons are working but it means that your WP Cron system is probably OK.

Note: You can trigger WP Cron manually. The first thing to do is to construct the link, and this is how to do that:

  1. Take your admin URL, e.g. example.com/wp-admin/
  2. Replace "/wp-admin/" with "/wp-cron.php?setcronjob"

The link will look like this:

example.com/wp-cron.php?setcronjob

Just open that link in a separate tab and the WP Cron will be triggered.

What issues do WP Cron errors cause?

If the cron is breaking, isn't running correctly:

  • WordPress automatic updates will not run
  • Checking for plugins or themes updates will fail
  • Schedules posts will not be published
  • If WordPress does not use a real cron job for scheduling and other related tasks, email notifications, automatics renewals, billing charges, in/out of stock notifications will fail.
  • Site backing up will fail for backup plugins that depend on the cron

Also,

  • There can be a long delay between updates released, and updates installed
  • Premium plugins don’t link in their update code correctly

    Certain premium plugins haven’t tested their custom update code with the WordPress cron. This means that when the cron is run, their update code doesn’t work and automatic updates of premium assets will fail.

These are just a few of the most noticeable problems we’ve seen.

Please note that, if the cron isn't working, all the automatic tasks will fail.

How to fix the WP Cron

The WP Cron can be problematic and narrowing down where a cron is crashing is tricky work.

We highly recommend you to read this article here.

You can also read:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us