Recently, while working extensively with WordPress, I’ve come across the problem with WordPress’ Missed Schedule issue. Every now and then post(s) scheduled in a future date does not get published and shows up as “Missed “Schedule” on admin side. Searching on net is not giving me much of a direction than people suggesting to run wp-cron manually etc. So I decided to to dig into the issue and trace the root of the problem. So here is Part 1 of my finding. I am still digging to find real issue and the way to fix it.
So far I’ve manually ran part of wp-cron to find details. “wp-cron.php” makes a query into the wp_options (wp can be different as per the prefix you’ve used during WordPress installation) table in WordPress database to find the current/future processes to run. So what comes back from the query is an array like:
[1314032200] => Array (
[publish_future_post] => Array (
[asdasd0880as0dasdasd08] => Array (
[schedule] =>
[args] => Array (
[0] => 19999
)
)
)
)
Here the key of the array is the unix timestamp when the post should be published. Everything seems fine until I looked at the list of scheduled posts and for one given day I had 4 articles scheduled. But my array from _get_cron_array function only lists 1 post. 3 out of 4 articles were scheduled at the same time (for example, 2PM) so that lead me to think probably all three posts scheduled at 2PM have the same timestamp, therefore, the key is being overlapped. But it seems WP (is smart enough to) set the time at different seconds of the hour it is scheduled for. And that also explains why the 4th article (which was scheduled at a different time) was not showing up in the list.
For example, if I schedule 2 posts at 4PM WP will schedule one at 4:00:22 and one at 4:00:40. I am not sure about the pattern WP uses for the second but one thing I know when I’m scheduling a future post it only lets me specify hour and the minute. It makes sense because if we have the same timestamp it will only take one item for the timestamp in the array.
Now, like I explained the array is still missing the articles in the cron array although they have different timestamp. So I tried looking more. I let the time span to the next scheduled post and have proven that the article(s) that I do not see in the array (although they are scheduled) got missed. To quickly see what is in the array you can have a test.php in the root of WP installation and try the following code:
require_once('./wp-load.php');
$crons = _get_cron_array();
echo "<PRE>";
print_r($crons);
echo "</PRE>";
This will print the list of scheduled posts (if any). So before I dig into the code even further I decided to check the list for the next set of scheduled posts. I found another few those did not show up in the array. So I decided to edit one of the articles that is missing in the cron array. I clicked on EDIT and just pressed the UPDATE button (without modifying anything). Now when I went back to my array (refreshing test.php) I found the article listed in the array!! Now, I’ve let the cron run for the second round and the articles those were not in the array got missed and the one I manually updated got published.
So, now my next step is to dig into the scheduling functionality of WordPress to understand how does this work and what causes some of the articles getting missed from the scheduled list. I will post my finding soon after I have more on this topic.