Fix Missed Schedule in WordPress by Using Linux Cron for your WP-Cron Tasks

Have you ever been working with a WordPress site and found things labeled as “Missed Schedule” or had various scheduled tasks be incredibly late/delayed when they were supposed to be set to run/post/whatever at X time in WordPress? That’s probably because wp-cron isn’t using the proper linux cron to set these tasks to work. It’s a “pseudo-cron” service which means while it functions a lot like cron–it’s not cron like you’d see in Linux, Mac, or Unix. It’s actually a far less reliable system to be using.

With cron you can set specific scripts, commands, and other tasks to run in your operating system at specific intervals of time, be it every 5 mins, every month, or every year as long as your operating system is up and running the job will be ran at the interval specified in cron. Most automated tasks in Unix based operating systems work with cron. The difference with “pseudo-cron” is that it doesn’t run independently. It requires something to trigger it, before it can trigger the events it has in its Queue.

With WordPress that “trigger” is someone visiting the website. Someone actually has to pull up your WordPress website in order for anything in wp-cron.php to run. So if you have a post set to go out on May 15th and no one visits the website until May 17th you’ll find yourself with a “Missed Schedule” error in WordPress.

I’m sure you can see where this quickly becomes a much less reliable solution than the standard linux cron, especially if your website is a low to medium traffic website that doesn’t get hits every day.

Thankfully you can configure your server to manage your wp-cron tasks automatically using the proper cron vs the pseudo-cron service built into WordPress.

Here is how you’d do that…. (with cPanel anyways)

First we have to disable cron within WordPress, since we will no longer be using it. To do that simply open your wp-config.php file and drop in the following line:

define('DISABLE_WP_CRON', true);

Next we will want to open up your cPanel account and locate the Cron Jobs tab as shown below:

Screen Shot 2013-05-03 at 2.46.50 AM

Once inside of the Cron Jobs tab you’ll have the following screen:

Screen Shot 2013-05-03 at 2.50.32 AM

Under Common Settings select Run Every 5 Minutes and then enter the following command (replacing with your own domain) in the Command section:

wget -O /dev/null

What this will do is trigger the wp-cron.php file every 5 minutes automatically–even if someone doesn’t visit your website. So this means rather than relying on a random visitor to trigger your cron service with WordPress, you’ll have 100% accuracy in all scheduled tasks within a 5 minute window.

That’s it, congrats you just fixed the pesky “Missed Schedule” error in WordPress and made scheduled tasks in WordPress just much more reliable and awesome in general.