WordPress Cron Can Kill a Website

I have run into this several times now so I thought I would write a quick article on it. It seems that WordPress’s cron really mess up a website.  Too many cron events will slow down your website. It can even cause timeout errors and out of memory issues.

What is cron?

Cron is basically a system to run programs in the background operation of your website. For a detailed explanation find out more here: Cron Info.

WordPress cron runs every time someone goes to your website. This is great as many plugin creators design software to do all kinds of fun and interesting things with your website. The downside is that these cron tasks can add up if not properly cleaned up. The average WordPress blog creator may not even know this exists. Worse, it can get full of all kinds of useless or out of data cron jobs.

The trouble is all these cron jobs are still queried, and possibly run, every time someone goes to your website. Over time this will certainly slow down your site. Especially if you experiment with many different plugins as many of them will leave residual cron tasks when they are uninstalled.

Check the WordPress Cron

First check your the WordPress cron and see if there is an unreasonable amount of cron jobs.

What’s unreasonable? That can vary greatly but I would say over 50 and you probably have too many. On my latest website with issues there were almost 20,000! Hard to say where they came from, but they needed to be cleared out!

First and foremost always backup your database when doing anything in it.

I prefer to go directly into the database with phpMyAdmin. Run the following SQL query.

SELECT * FROM `wp_options` WHERE `option_name` = 'cron'

This will retrieve the record of your cron jobs. In the option value field you will see something like this.

a:20:{i:24321341;a:1:{s:29:"something_job"...

The only thing you really need to worry about is the very beginning of this entry. It will tell you how many cron jobs are present. In this case, there are 20.

a:20:{i:24321341;a:1:{s:29:"something_job"...

In my case it looked like this.

a:19722:{i:24321341;a:1:{s:29:"something_job"...

19722! Yikes. This was pretty much crashing the website. Good news though. It is really easy to fix. Simply delete the cron entry and because of the magic and quality of WordPress the cron will be rebuilt the next time someone goes to your website. Easy as that!

DELETE FROM `wp_options` WHERE `option_name` = 'cron'

Now you may need to go though and check your plugins, anything that schedules tasks, and verify that they are still scheduled and working. In most cases they will be. If not, set up the task again. These are things like calendars, auto backups, auto posts etc. All of these are done through cron jobs.

There is also a pretty cool plugin you can use to look at your cron jobs in a more UI friendly way.

https://wordpress.org/plugins/wp-crontrol/

Hopefully this helps you clean up and speed up your WordPress site!