How To Optimize WordPress Cron On WordPress Multisite

WordPress Cron is a feature that has proved to be very useful in WordPress. It is commonly used to do the following:

  • Run cleanups. For example, in WooCommerce there is a cron scheduled to clean up and delete old session data.
  • Scheduled backups.
  • Scheduled posts. It allows you to auto-post articles which improves the publishing experience.

If WordPress Cron did not exist, your website’s database would be filled with thousands of old useless sessions.

Issues with Scaling the WordPress Cron

Now let’s talk about scaling WordPress Cron and the issue multi-site users have with it.

WordPress Cron is not a real cron job in the sense that it does not run on a timed interval. Instead, WordPress Cron runs whenever there is a request made to your website. It is then triggered and looks to see if there are any tasks for it to do.

This has a couple of issues, particularly on large multisite installs. When you’re running a popular website that has thousands of visitors every day you are wasting a lot of server resources. Think about it. If you’re blog gets 1,000 visitors a day, the standard WordPress Cron will attempt to run (in theory) 1,000 times in that day. This is clearly not an efficient way to run scheduled tasks.

If your website is getting 50 visitors a day, you won’t notice this. The issue comes into play when scaling websites and larger enterprise environments when there is a lot of content and a lot of visitors.

Issues with the WordPress Cron in a Multisite Install

As a WordPress geek, I have been wanting to incorporate WordPress Multisite in a project pretty badly. Just haven’t gotten the proper idea or use for multisite yet. WordPress Multisite is truly a website geeks dream of managing website’s because everything can be managed from one place.

However, a common issue I see when working with some of my larger client’s multisite installs is these sites often use the default WordPress Cron.

Fixing WordPress Cron on Multisite Installs

There are a couple of ways to go about fixing the WordPress Cron on multisite installs. On a recent client’s site, I had to find a solution for this. WP ClI would have worked but that was too complicated for a casual WordPress user. The client needed a solution he could manage himself.

I was scratching my head on this for awhile. I was trying to find an easy fix, without having to create a bunch of individual WordPress Cron tasks. In the process I found a very handy little plugin called Multisite System Cron.

Multisite System Cron was a good compromise because it allowed the WordPress Cron to be updated automatically. The client could update the interval to shorter or long as more multisite installs were added, without even having to touch the command line.

The plugin was very simple to use out of the box because it didn’t require much configuration. I only had to configure one cron job and follow two simple steps within the plugin. Those steps are the following:

  1. Disable wp_cron from the wp-config.php file. (I had completed this already)
  2. Copy and paste the cron job tasks it provides.

After setting up the plugin, I saw a decrease in server resources on the client’s website and the cron jobs were running correctly.

For my WordPress CLI friends, please check this code out on Github.

Remember, the best way to manage WP Cron in multisite is to create your own cron job. Do not rely on WordPress Cron.

scott hartley

About the author

Scott is a web performance geek, lover of all things coffee, and avid video game player. His WordPress work delves into web performance, web security, and SEO.

Leave a Comment