WordPress – How to limit wp-cron cron job run times

By default WordPress will run an artificial ‘cron job’ once every minute.

These cron jobs are used to maintain WordPress in the background by doing tasks like publishing scheduled posts and triggering the wp_schedule_event action hook – which third-party plugins you have installed may be using.

There are two issues with this cron job –

  1. In some circumstances the cron jobs can be ‘stacked’ – meaning they can run more than one at a time, leading to excessive resource use and potentially your host shutting your website down.
  2. Checking and running the cron jobs every 60 seconds decreases the page load speed — especially if you don’t have any caching.

There are various solutions to this, some people choose to completely disable the cron job by using DISABLE_WP_CRON in the wp-config.php, for example

define('DISABLE_WP_CRON', true)

This of course would completely break scheduled posts and any other features that rely on the cron job.

Often this is taken a step further by setting up a real cron job using their host management tools (normally cPanel).

WP_CRON_LOCK_TIMEOUT

More recently another solution has been made available. WordPress 3.3 introduced WP_CRON_LOCK_TIMEOUT which allows you to define the period of time the cron job will run – this allows you to change it from the default 60 seconds to any other amount of time – such as 60 minutes (3600 seconds).

To configure this option you need to access the WordPress configuration file, usually you would use an FTP connection or access to the WordPress files using your hosts cPanel.

Open wp-config.php

At the very bottom add the following line, note that the number is seconds – 3600 is 60 minutes.

define('WP_CRON_LOCK_TIMEOUT', 3600);