One thing you might not know about this site is that I don’t actually wake up each morning and type up a new blog post – I actually write them ahead of time, and set them up to be published at a future time. Unfortunately this doesn’t always work, such as what happened to me a few weeks ago.
I use WordPress to host my various blog sites, and it has a feature called “scheduled posts” – set the time you want the post to go online, and in theory they’ll magically appear in the future, without any manual intervention.
For this magic to happen, WordPress has to regularly check what time it is, check if any posts are due to be published, and if so, publish them – a process that is triggered in two different ways:
- run the check every time someone visits the site, or
- run the check based on a cron job (scheduled task)
I first encountered troubles with my scheduled posts in early April.
Why has my blog robot been broken all week?
— Marcus Wong (@aussiewongm) April 2, 2015
My initial theory was that a recently installed WordPress plugin was to blame, running at the same time as the scheduled post logic and slowing it down.
Looks like my blog robot is working again (I think the ‘Broken Link Checker’ plugin was making the WordPress cron page time out)
— Marcus Wong (@aussiewongm) April 10, 2015
I removed the plugin, and scheduled posts on this site started to work again – I thought it was all fixed.
However, a few weeks later I discovered that new entries for my Hong Kong blog were missing in action.
Turns out my blog robot still isn’t working right, as it missed a post from April 8th. 🙁
— Marcus Wong (@aussiewongm) April 14, 2015
I took a look the the config for my cron job, and it seemed to be correct.
*/2 * * * * curl http://example.com/wp-cron.php > /dev/null 2>&1
I hit the URL featured in the command, and it triggered the publication of a new blog post – so everything good on that front!
I then dug a bit deeper, and ran the curl command directly on my server.
[email protected]:~$ curl http://example.com/wp-cron.php <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.example.com/wp-cron.php">here</a>. </p> <hr> <address>Apache Server at example.com Port 80</address> </body></html>
Bingo – I had found my problem!
The end result was my cron job hitting a URL, finding a redirect but not following it, resulting in the PHP code never being executed, and my future dated blog posts laying in limbo.
my fix was simple – update my cron job to hit the www. version of the URL, and since then, my future dated blog posts have all appeared on the days they were supposed to.
About the lead photo
The train in the lead photo is the Melbourne-Sydney XPT – on 11 July 2014 it derailed near North Melbourne Station due to a brand new but poorly designed turnout.