Have your scheduled posts ever missed their schedules in WordPress? Did you find a solution to the problem? How did you fix it (if you fixed)?
One of the issues people say they started to notice was the missed schedule errors since WordPress version 3.5. A lot of people have experienced this error after they implemented W3 Total Cache plugin.
Digging further, some people say the problem arises when Database Caching or Object Caching is enabled in W3 Total Cache plugin. There are many different opinions about it. However, it’s not clear if W3 Total Cache will ever be able to fix this problem.
I am going to explain this in a moment. However, let’s see how the mechanism works first!
How WordPress Runs Scheduled Tasks Using WP-CRON
The more you know about WordPress, the more you come to appreciate how much this little CMS does for you. It’s amazing how many things WordPress does in the background so that you and I can focus on producing content and marketing without concerning ourselves with technology too much!
One of the most powerful features in WordPress that most people don’t even know or discuss is the ability to run cron jobs using the WP-CRON.php file.
Every WordPress installation comes with WP-CRON.php file with functions to create/execute cron jobs that can help run scheduling tasks such as:
- Checking for theme & plugin updates (Now you know how plugin updates happen)
- Publish scheduled posts
- Sending pingbacks
- Executing scheduled WordPress emails to subscribers etc.
- much more…
Unlike regular cron jobs on any server which run at a specific time based on the server’s settings, the WP-CRON process runs every time someone visits your WordPress powered website.
This makes a WordPress site run properly on different kinds of server setups because it eliminates a lot of server-specific requirements. On every page load, WordPress checks to see if there is a need for WP-CRON to run. If there is a need, it tries to make a request over HTTP to the WP-CRON.PHP file.
While this works great for most part, it can have some issues for some people and missed scheduled error on your posts in WordPress is just one of them.
Issues With Cron Job Execution In WordPress
Here are some of the most common issues with WP-CRON that people run into although this list is not comprehensive:
1. Missed Scheduled Posts
This is the most widely reported issue on the web. It is the issue which I have faced often on my websites as well.
Usually, this happens after implementing W3 Total Cache (W3TC) WordPress plugin and the reason is very simple.
WP-CRON is supposed to be invoked when a page load is requested. When caching is enabled, chances are that the page is served through the cache and WordPress is not called upon to do anything. Thus, the cron job is not created causing the missed schedule error.
The plugin does a good job of identifying the posts that missed their schedules every 5 minutes and publishes them. This is a great way to solve this problem as long as you know how to install and activate a plugin in WordPress.
However, because it’s a plugin, that’s not the solution I prefer for the following reasons:
- Plugin conflicts can cause this plugin also to malfunction at times.
- It adds one more plugin to your WordPress making it a bit heavier especially since this is not the only way to fix the problem.
- If the plugin author doesn’t update the plugin, it may become a headache at some point in future.
I am going to talk about a better solution when we are done talking about these problems. Now, let’s continue discussing the other issues.
2. Scheduled Tasks Not Executing As Expected
You might have membership based websites where you have scheduled emails to go out to members based on certain criteria. All of a sudden you notice that those emails didn’t go out.
Sometimes, people complain that automatic membership renewal reminder emails don’t go out to their members.
Problems like that can also happen due to the exact same reason. If page load event is not registered, WordPress is not going to invoke WP-CRON.PHP thus missing scheduled executions.
Now, as you can imagine, you need one more plugin to solve this problem because Missed Scheduled Posts plugin isn’t going to help in this case. So, how many plugins you can keep installing, right?
3. Cron Jobs Not At All Executing
You will be able to identify that all of the scheduled tasks including missing post schedules aren’t happening because the WP-CRON is not creating any cron jobs due to incorrect setups or plugin conflicts. Sometimes, it could be because of the firewall on your server.
Again, this is just another way at talking about the same problem. WordPress isn’t going to execute any scheduled task if cron jobs are not even being executed.
4. Multiple WP-CRON Jobs Running On High Traffic Websites
On high traffic websites where WP-CRON.PHP is executing fine, this problem is more common and for obvious reasons.
Every page load is supposed to execute WP-CRON.PHP by definition. Now, if you have 20 thousand page views a day, those many times the cron job is being created and some of those can run for a minute and more.
This causes system administrators to get warning emails and sometimes, they see it as an issue based on overall load on the server.
5. Too Much CPU Resource Usage By WP-CRON
This is another problem that can cause overload on the server. Not only human beings but bots visit your web pages too. Do not forget the spambots!
Remember, your server is trying to executing WP-CRON on each page load irrespective of who is trying to visit the page.
This puts a lot of load on your server. Sometimes, depending on who your web host is, it can lead to resource usage problems for your server.
Why would you want your WordPress to run WP-CRON.PHP 20 times a minute? It just doesn’t make sense, right?
A Better Solution – One Solution For All Scheduling Problems
All of the above problems have one source – WordPress trying to invoke WP-CRON-PHP on page load event.
The ideal solution, I believe, will be to change the way WP-CRON.PHP is executed so you can have better control.
Whether you are on a shared hosting server or you have your own dedicated VPS or dedicated server, you should be able to easily achieve this. If you do not understand, you can always get help from your hosting company in getting this done.
Okay. Let’s talk about the solution now!
The idea is the disable the default behavior of WP-CRON.PHP execution and then schedule a new cron job to execute it every 15 or 30 minutes. You can also schedule it to run every 6 hours if you don’t have a frequent need to run cron jobs.
Step 1: Disable Default WP-CRON.PHP Behavior
This steps requires you to access your WP-CONFIG.PHP file to edit. You can get this file either using FTP or using your cPanel account. Once you have the file open, you are ready to edit this file.
Assuming that you know how to edit this file, you need to add following line into this file. I prefer to add this line right after define(‘DB_COLLATE’, ”); statement although you can decide your sweet spot depending on your preference:
/** Disable default WordPress cron execution plan*/
Now, save WP-CONFIG.PHP in your WordPress installation directory. The first step is now completed.
Step 2: Setup A Manual Cron Job For WP-CRON.PHP Using cPanel
Now that you have disabled the default behavior of the cron job execution by WordPress, it’s time to setup a new cron job on your server to execute WP-CRON.PHP at a regular interval. This cron schedule will consistently execute without any interruption.
According to some web hosting companies, having the WP-CRON.PHP script run every 6 hours is perfectly fine for most WordPress users. However, if your web host allows, you can schedule WP-CRON.PHP to be executed every 15 minutes or every 30 minutes.
Even if you execute WP-CRON.PHP every 15 minutes using an external cron job, you will only have 96 executions a day. Compare that with the load on server for thousands of executions a day if you have only a few hundred visitors a day per website on that server.
Follow these steps to create a manual cron job using your cPanel account:
- Log into your cPanel account
- Scroll down to find the Advanced section and then click on Cron Jobs icon as shown in the screenshot below:
- Enter an email address to receive notification in case of errors and also choose the time interval for your cron job in the Common Settings drop-down as shown in the image below:
As you can see, I chose 30 minutes interval as an example.
- Now, the most important step. Fill in the command (or set of commands) to create your cron job and click Add New Cron Job as shown in the screenshot below:
As you can see in the above image the a cron job is being created that changes directory to take control into your WordPress installation directory where WP-CRON.PHP is present and then it invokes the WP-CRON.PHP in quiet mode. The syntax is:
For example, if your hosting account’s wordpress is installed in “/home/user5”, your cron command will look like this:
If you have hosted a subdomain in a subdirectory within your “public_html” by name “subdomain1”, your command will look like this:
The idea is to make sure cron job goes into the directory where WP-CRON.PHP is installed and then executes the program.
At the end of this step, your WordPress website will be reliably and consistently running your scheduled tasks via the WP-CRON.PHP script, but only at set intervals. No more plugin conflicts or cache plugin effects will adversely impact your scheduled tasks.
If you think about it, what a relief knowing that your scheduled tasks are not overloading your server in anyway and also running consistently no matter which plugin is having error and which is running fine.
Your Turn To Share – Have You Faced These Challenges?
Have you run into issues of missed schedules on your WordPress installations? How did you handle it?
Do you any other or even more effective solutions to run scheduled jobs more reliably on our WordPress websites?
Please feel free to share your experiences and thoughts to add value. Thank you kindly as I look forward to learning from you!