If a Visitor is There to See: WP-Cron and the Clock of the Long Now

What do WP-Cron and the 10,000 Year Clock of the Long Now have in common?

They both only tell time if someone is there to see them.

Huh?

Most clocks have a power source to keep their faces updated. But in a clock buried deep in a mountain, why waste energy updating the clock face if no one is there to see it? Instead, why not use the humans who come to see it to wind a falling weight that will update the clock face with the current time.

Hillis and Brand plan, if they can, to add a mechanism whereby the power source generates only enough energy to keep track of time; if visitors want to see the time displayed, they would have to manually supply some energy themselves.

https://en.wikipedia.org/wiki/Clock_of_the_Long_Now#Displaying_the_time_and_date

Okay, cool. Now what about WordPress? Doesn’t it have a clock?

Actually, no. Unlike its cron namesake in Linux, WP-Cron isn’t a clock at all. There are some historical conversations you can look up in IRC and trac (fun fact: it used to be called pseudo-cron!) about why this is the case, but the short version is that WordPress is made to be an application running on top of a system, and it isn’t guaranteed that it will have access to the system’s scheduler (on shared hosts, for example), so instead with WP-Cron, all scheduled tasks are put into a queue that is checked with every page load, and will run at the next opportunity (meaning the next page load). While you can’t be 100% sure when your task will run, you can be 100% sure that it will run eventually. [Source]

If you are very particular about your WP posts going up at a certain time, there are ways you can hack pageviews, such as setting a service like Uptime Robot to ping your website every minute. Or you can move to a host like WordPress.com, WordPress VIP, or WPEngine that has a bit tighter integration with the system clock and wp-cron. Or you can roll your own using Lingon to interface with macOS’s launchd.

So if a post gets published on WordPress, it is because someone was there to see it, and if someone sees the time on the Clock of the Long Now, they had to crank it themselves. Age-old conundrum solved.

h/t Mark Drovdahl for a conversation that sparked this musing


Leave a Reply

Your email address will not be published.

%d bloggers like this: