← All posts

Cronbot Is Now Written In Go

By ·

Cronbot is the free, optional service in Docket Cache that pings your site every hour. Its main job is to make sure the Docket Cache garbage collector runs, even when nobody visits your site. We have rewritten the Cronbot server in Go. The new server is already live, and you do not need to change anything on your site.

Why Docket Cache needs a ping#

Docket Cache keeps its cache as files on disk. The garbage collector keeps that folder in good shape. It is a WordPress scheduled task that runs every 5 minutes, and it does four things.

The problem is that WordPress scheduled tasks, called WP-Cron, only run when someone visits your site. On a quiet site, the garbage collector can go hours without running, and the cache folder can grow past its limits. On shared hosting, that can mean too many files or too much disk space. On a site that turns WP-Cron off with DISABLE_WP_CRON, the garbage collector does not run at all unless something else starts it.

Cronbot is that something else. Once you connect, Cronbot pings your site every hour. Each ping runs the scheduled tasks that are due. Most importantly, that includes the garbage collector, but it also runs other WordPress tasks, such as publishing scheduled posts, sending emails and checking for updates.

First, you click Connect, and your site tells the Cronbot server. Next, Cronbot pings your site every hour. Your site then runs its scheduled tasks, such as the Docket Cache garbage collector, publishing scheduled posts and checking for updates. Last, your site sends a short reply, and Cronbot picks the next ping time, which is 1 hour when all is well, or later if the site is busy or answers with an error.
How Cronbot works

Connecting your site#

Cronbot is off by default. To turn it on, open the Cronbot screen of Docket Cache in the WordPress admin and click Connect. The same screen lists your site's cron events and when each one will run next.

The Cronbot screen of Docket Cache with the Service Status shown as Not Connected, the Connect button, and a list of cron events. Some events are more than a day late.
The Cronbot screen. On this quiet test site, some tasks are already more than a day late.

After you connect, the screen shows when the last ping arrived and when the next one is due. Click Test Ping at any time to check that Cronbot can reach your site. To stop, click Disconnect.

Why we rewrote it#

The first Cronbot server was a small PHP project. A cron job on the server started a shell script, which used GNU parallel to start a new PHP process for every ping, 3 at a time. Each connected site had its own PHP data file.

That worked well for years. Today, about 3,500 sites are connected, and the old design was starting to show its age. Many small parts had to work together, pings could only go out 3 at a time, and there was no easy way to see what happened over a day or a month.

Before, a cron job started a shell script, which used GNU parallel to run 3 pings at a time, each in a new PHP process, with one PHP data file for each site. Now, one Go program finds the sites due for a ping, sends 20 pings at a time and answers Connect requests. It keeps all sites in one SQLite database, plus a history file for each month.
The old PHP server and the new Go server

What is better#

What stays the same#

What Cronbot knows about your site#

To connect, the plugin sends your site address, your timezone, your Docket Cache and WordPress versions, and, on a multisite network, the number of networks and sites. The server also sees the IP address the request comes from. After each ping, your site sends a short reply about the tasks it ran.

Cronbot never sees your posts, your users or your passwords. We use this data only to run the service and to learn which versions of WordPress and Docket Cache are in use.

Keeping it free#

Cronbot is a free service, and running a server for thousands of sites costs money. If Cronbot helps you, please think about sponsoring Docket Cache. Read more in Our First Merchandise.