Alfonso Catrón

WordPress Engineer, Support & Tooling

WP Cron and caching plugins: a tale

WP Cron can be a misterious thing, when you check the WordPress docs you will find an explanation like this one:

WP Cron is WordPress’s way of processing scheduled tasks at specific intervals. It is very important not only for WP Rocket but for anything that requires automatization within a WordPress install, like automatic post schedules, plugin updates, etc. These tasks can be virtually anything that requires periodicity and automation.

And, when you mix it with caching plugins things can become really complex. I wrote a story about WP Cron. What follows is a free interpretation of WP Cron in a literary way.


Imagine a bus terminal in a town. In this terminal there are passengers, waiting for buses at different platforms. Since there are different buses and these are passing every hour, once per day, twice a day… each passenger has a ticket because, of course, they are waiting for a specific bus.

These buses are very organized, they are all waiting at the terminal gate. Because I forgot to mention that, the engineer who built these terminals, added a gate. And no bus can enter if the gate is closed, so the buses are waiting for the gates to open

The engineers had the idea to add a big red button to open the gate and, the pedestrians in the town are responsible for pressing this button. So, they know that each time they pass by the gates of the terminal, they have to press the button so the buses can enter. And the gate closes itself after some seconds.

Of course, this is not always working as expected. Things happen and sometimes there are no pedestrians at all: it’s too late in the night, or is freezing…

There are some towns that even implemented teletransportation, and in these cases, there are almost no pedestrians at all!

Imagine the situation! the gates are closed, passengers screaming, babies crying, hundreds of buses collapsing the gates! But then…. a random pedestrian passes by and bum! he presses the big red button… INSTANT CHAOS! some buses rush to the gate while passengers start running to get their bus.

To solve this, the town council calls a group of experts and (of course) more engineers. After days and days of endless discussion, they notice a person, probably tired of all the chaos, using an old blue tweed jacket and a hat, standing by the red button, pressing it every 5 minutes. He even had a clock to check it!

What a surprise! The peace is restored. All the buses are running as expected and everyone is happy.

So the town council decides to hire him and offer him a job as a Terminal Guard. From that day the peace is restored. The guard is patiently waiting at the door, watching his clock. And every 5 minutes, he just presses the big red button.


CAST

– 🏫 This Terminal is WP Cron: the *(in*)famous WordPress scheduling tasks system
– 👩🏻‍💼👨🏼‍🌾:👦🏻👵🏽 the Passengers are the Tasks
– 🚌 the Buses are the Schedules
– 🔴 the red button is wp-cron.php
– 🚶🏻‍♀️ the Pedestrians are the Site Visitors
– 👮🏻 the Terminal Guard, is the server-side CRON Job
– 🚀 Teletransportation is of course WP Rocket, or your favorite caching plugin


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *