What is the WP Cron?
The WP Cron is the scheduling system within WordPress. WordPress needs to work everywhere in lots of different systems. This means WordPress cannot rely on there being a cronjob service on the server it's currently installed on. The developers came up with a workaround for this by creating the wp-cron.php file.
How WP Cron works is that every time WordPress is loaded from either the frontend or backend, the wp-cron.php file will run. When the wp-cron.php file runs, it will check for scheduled tasks in the database and if it is at or past the time for the task to run, wp-cron.php will fire off the scheduled event.
WP Cron handles all automated processes in WordPress, including scheduled posts, sending emails, checking for available updates and much more. BackupBuddy uses the WP Cron to generate backups, fire off scheduled backups, send files to various remote destinations and tons more.
How does WP Cron work?
As stated previously WP Cron is a simulated cron meaning that it simulates the functionality of a real cronjob service. An actual cronjob service like you would find on any Linux distro fires off scheduled tasks exactly when they are supposed to happen. So if you schedule a task to run with a Linux cronjob to run at 1:00 AM it will always run at 1:00 AM assuming the system is turned on.
Well, that is not always the case with how WP Cron works in WordPress. Let's say you schedule a post to be published in the middle of the night at 2:00 AM on a site that does not get very much traffic. So if no one visits or accesses your site till 2:15 AM, then the scheduled post will be published at 2:15 AM.
Remember for wp-cron.php to run your site must be accessed through the frontend or backend. So because you did not have a visitor on your site until 2:15 AM, that's when the scheduled post was published even though you scheduled it to go out at 2:00 AM. This is why we say WP Cron is a "simulated cronjob service" because your site needs to be pinged for WP Cron to run.
How to tell if WP Cron is working properly on your site.
By default, WP Cron is enabled in WordPress. Though some times a host can have it disabled as it does use a small number of resources.
Other plugins can block or break WP Cron as well. Luckily, BackpuBuddy has a few tools to help you debug/troubleshoot scheduled tasks on your site.
First, there are a couple of items on the BackupBuddy Server Tools page that detects whether WP Cron is enabled and whether or not it is working properly.
In the image below you can see that Backupbuddy will report whether or not WP Cron is enabled. Then it will also actively test WP-Cron in the wp-cron.php Loopbacks item and report its output. So you will see errors there if something is conflicting with or breaking WP Cron.
Secondly, back on the BackupBuddy Server Tools page, click the Cron tab. This will show a listing of all scheduled tasks that have been registered through WP Cron.
Looking at the screenshot below you can also see the time of the next run for each cronjob, as well as the interval it is set to run at (once daily, once hourly, once weekly, etc....).
You can also hover on any of the items and click the Run cron job now option. This will force that scheduled task to run at that moment but it will not modify its next time to run and will continue to run as normal going forward even though you clicked Run cron job now. So if you want WordPress to check for a new version click the Run cron job now link under the scheduled event wp_version_check.
If you wanted WordPress to check for plugin updates but did not want to wait for the cron job to fire off, you can go here and click the Run cron job now link for the wp_update_plugins. This will force WordPress to check for plugin updates immediately.
Also, you can delete cron jobs that you do not want firing off. In some cases, other plugins can have cron jobs pile up, making it impossible for WordPress to run any other cron jobs. You can go here and remove the corrupted cron jobs or cron jobs that have built up over time.
What to do if your host is blocking WP Cron.
First, we should check your site's wp-config.php to see if they added the line of code to disable WP Cron.
To edit your wp-config file, you'll first need to log into your cPanel on your server or access your site files through (s)FTP. You should find this file in the main directory of your site.
Once you've found your wp-config file, you'll need to open it so that you can edit it.
Looking at that file, you'll want to find the following line and delete it:
define( 'DISABLE_WP_CRON', true );
Be sure to save your file once you've made this change and re-upload the file if necessary.
What if I need to disable WP Cron?
If you decide you need to disable WP Cron for any reason, you can do this very simply. You'll just edit your wp-config.php file again and add the following line:
define( 'DISABLE_WP_CRON', true );
Once you've made your change, save the file and re-upload it if necessary. Just make sure you add your code after the opening
and before the closing
/* That's all, stop editing! Happy publishing. */
What do I do if I can't enable WP Cron on my server?
Sometimes hosts will block access to the wp-cron.php file and there is not a lot you can do about it.
You can, of course, add the line below to your wp-config.php to enable alternate cron.
define( 'ALTERNATE_WP_CRON', true );
Keep in mind, though, that alternate cron is not as reliable as WP Cron and also adds doing_wp_cron to the end of your URLs when accessing your site. Regardless, it is worth a shot to try the alternate cron if the default WP Cron is being blocked by your host.
If a host is going to go out of their way to block WP Cron, which is a main feature of WordPress, it might be better to switch to a host who fully supports WordPress and its Cron system as it will save you lots of headache in the future.