WordPress wp-cron.php consuming too much memory and cpu

What does wp-cron.php do, anyway?

wp-cron.php is a script that carries out the periodic maintenance tasks that WordPress needs to do. This can include managing:

  • scheduling posts to appear in the future
  • emailing notifications of new comments or other events
  • running plugins such as Akismet to filter comments for spam

The scale of the problem with wp-cron.php

On a small website with a few pages and a few hundred visitors a day wp-cron.php isn't a problem, but imagine a larger website with maybe a 100 visitors an hour. If each visitor read your home page, and 2 others, that would mean that wp-cron.php is being called 300 times an hour, 7200 times a day and so on. Plus, on a busy/large website, wp-cron.php might take a few minutes to run.

Multiple copies of wp-cron.php can be started at once as well because people don't wait in line to view your web pages! This means that more memory is needlessly consumed. It all snowballs into a horrible resource hog.

We've seen some busy sites running multiple instances of wp-cron.php tasks consuming over 200Mb of virtual memory each! This will quickly exhaust your cPanel accounts' allowed memory allocation - that's if it hasn't exhausted your CPU allowance already. This may cause your website to fail to operate correctly.


How to stop wp-cron.php hogging resources

The first thing we need to do is stop WordPress from running wp-cron.php willy nilly when it feels like it! Fortunately, this requires no more than entering an extra line in wp-config.php, which can be found in the base directory of your WordPress installation.

Just add this line either to the top (just after the <?php tag) or bottom of the file:

define('DISABLE_WP_CRON', true);

This will disable wp-cron.php from being called by WordPress itself.

The next step is to setup some way of running the script manually at a regular interval. The way to do this is by creating a cron job (which can easily be done using the Cron jobs icon your cPanel account). To find out how to setup a cron job in cPanel just read or watch these articles:

  • How to configure scheduled tasks using Cron in cPanel
  • How to configure a cron job?

Once you have decided how often to run your job, the Command to enter will be

/usr/bin/wget -O /dev/null http://www.mydomain/wp-cron.php?doing_wp_cron

Obviously, replace "www.mydomain" above with your own website address.


How often should wp-cron.php run?

How often do you update or tend to your website?

As a rule, if you only check your website once a day, then run wp-cron.php once a day.

  • 4 Users Found This Useful
Was this answer helpful?

Related Articles

[Important] Wordpress Optimization Guide

Hey all,Wordpress is the one of most popular CMS used by All the Web Developers for wasy...

Wordpress Security

Hello,WordPress and other CMS Are easily hacked by SYMLINK We have already protected the server...

How to protect your cPanel/WHM from hackers ?

- Don't Save your Password in Browsers- Use Secure browser Google chrome for better security as...

Wordpress Security

Hello,WordPress and other CMS Are easily hacked by SYMLINK We have already protected the server...