Speed up WordPress by fixing the cron job

wordpress-iconWordPress needs to run certain things on a regular basis. It needs to check whether scheduled posts should be submitted, plugins and themes need to be updated, emails need to be sent and such.

To do this, WordPress has a wp-cron.php file. By default, this gets called every time someone accesses your site. I presume WordPress does it this way just in case the site administrator doesn’t have the facilities or wherewithal to create proper cron jobs.

As you might imagine, there’s an overhead in calling this every time someone accesses your site and it’s totally unnecessary. Instead you can call it with a proper cron job on a scheduled basis.

First of all you need to stop WordPress from calling this job every time the site is accessed. To do this, open your wp-config.php file in the WordPress root directory and add the following line:

define('DISABLE_WP_CRON', 'true');

Now you need to schedule a proper cron job to call wp-cron.php periodically.

If you’re on a CPanel system, log into your account, page down to the Advanced section and click on the Cron Jobs icon.

In the Add a New Cron Job section, select Once Per Hour from the Common Settings drop-down menu.

Then enter the following in the Command box:

wget -q -O – http://yoursite.com/wp-cron.php?doing_wp_cron > /dev/null 2 > &1

Replacing yoursite.com with the actual domain name of your site.

Then click the Add New Cron Job button.

That’s it. The cron job will now be called once every hour, which should be more than sufficient, rather than every time someone accesses your site.

Leave a Reply