Cron automated tasks overview

Last updated on
16 August 2023

This documentation needs review. See "Help improve this page" in the sidebar.

Most people don't need to read this page for most new Drupal installations because Drupal enables cron automatically for you.  It does this because your Drupal website must clean up every so often. This clean-up keeps your Drupal site working smoothly, for your user searches, user notifications, software updates, database health, and so much more.

Defaults suffice for most sites

The standard default cron settings suffice for most Drupal sites.  Current Drupal installs with an "automated cron" module built into the core.  By default, which you don't need to change. It executes cron about every three hours, more or less depending on your website traffic level.

Deviate from default if very high or low traffic

Read this page if you may need to deviate from the standard because your site expects extremely high traffic or expects very little traffic.  In those cases, adjusting cron settings will be important to keep your site performing at optimal levels for your traffic and computer hardware, by either increasing or decreasing the frequency of cron runs from Drupal core's defaults.

Setting up cron is an important step in the installation of your Drupal website and assists in the maintenance of the site's assets for search results, checking for updates to Drupal core and modules, and removing temporary files.

What cron does

A properly configured cron job executes, initiates, or manages a variety of tasks. For example, cron:

  • Updates the index of site content used by the Search module.
  • Queues feed to be updated by the Aggregator module.
  • Checks for available updates for the Update Manager module.
  • Performs routine maintenance tasks, such as removing older rows from logs, for the System module.
  • And more.

For those curious to know what cron does, just temporarily enable the "Detailed cron logging" checkbox at example.com/admin/config/system/cron.  Then press the Run cron button on that page. Then see what it did at example.com/admin/reports/dblog or from your database watchdog table.  Do this temporarily to prevent your database from filling up.

What is cron?

Cron is a daemon that executes commands at specified intervals. These commands are called "cron jobs". Cron is available on Unix, Linux, and Mac servers. Windows servers use a Scheduled Task to execute commands. The actual "cron job" is a time-triggered action that is usually (and most efficiently) performed by your website's hosting server, but can also be configured by a remote server or even from your own desktop.

What actually happens is that the cron job visits the cron.php file in your website at a URL like http://www.example.com/cron.php?cron_key=0MgWtfB33FYbbQ5UAC3L0LL3RC0PT3RNUBZILLA0Nf1Re. You can find the exact address of the cron.php file in the Status report at Administration > Reports > Status report (admin/reports/status) in the section Cron maintenance tasks.

How to enable cron

  1. Drupal core cron - easiest
  2. Drupal contributed cron modules
  3. Operating system programs like crontab, cPanel - the most reliable
  4. External programs EasyCron, Cronless

Easiest - Enable Drupal cron 

The easiest way is to let Drupal do it for you (which it does by default) using its built-in core "automated cron" system.  You can manage "automated cron" via Manage > Configuration > System > Cron (admin/config/system/cron). On a new Drupal installation, this should be on by default which you can check at example.com/admin/modules. The default frequency is every three hours. Cron then triggers by end-users visiting your site, no more frequently than every three hours. Note that for low-traffic sites it can also be desirable to create a cron job. If you want to disable the automated cron, change the 'Run cron every' drop down to 'never' (see Disable section on this page).

The automated Drupal cron system works with all operating systems because it doesn't actually involve the operating system's cron daemon. It works by checking at the end of each Drupal request to see when cron last ran, then if it has been too long, processing the cron tasks as part of that request.

Downsides of Drupal Cron

The two down-sides are (1) cron tasks only run when Drupal processes requests; and (2) the 'weight' (processing and memory) of running the cron tasks will be added to some arbitrary unknown page requests, which may slow down those requests, and has the potential to exceed memory limits on a complex page or site.

Disable Drupal cron

For performance reasons, or if you want to ensure that cron can only ever run from an external trigger (not from Drupal), it may be desirable to disable Drupal's automated cron system, in one of three ways:

  1. A preferred way to disable Drupal's core "automated cron" module is by unchecking it at example.com/admin/modules.
  2. To temporarily disable cron, set the "Run cron every" value to "Never" (e.g., at Administration > Configuration > System > Cron (example.com/admin/config/system/cron).
  3. For advanced reasons, another way to disable cron in Drupal add the following line to your settings.php.  Note that this fixes the setting at admin/config/system/cron to "Never", and administrative users cannot override it.
$config['automated_cron.settings']['interval'] = 0;

More reliable - Enable cron using an external trigger

The second way (which applies to any version of Drupal) is to create a cron job or use some other external (non-Drupal) method of triggering cron tasks, such as an external cron job service like EasyCron or Cronless or cPanel. This is the more reliable of the two methods (because it will always run on schedule), and it uses fewer resources (because the cron processing is not added to a page request). Therefore this is generally the preferred way to run cron when you have the choice. Note that if you create a cron job, you may want to disable Drupal's automated cron system entirely (see Disable section on this page).

For the beginner it might seem daunting to configure cron jobs using the cron command, but here's an example for you to follow.  For example, you can immediately execute cron from the Linux command prompt with two commands.  Use wget or lynx to access cron, depending on which command your operating system makes available, usually wget already exists.

Then, to make sure this is working, check your Drupal status report which shows the cron run time.  If this works for you and you want to try editing your Linux crontab file, here's a quick example of hourly cron.

  1. At the Linux command prompt, type crontab –e
  2. Go to the end then press the Insert key. Then type or paste below
  3. 1 * * * *  wget -O - -q -t 1 https://yourdrupalsite.tld/cron/Fe0lip-huaTyeUBYlCXbsc-QI-dw > /dev/null
  4. ESC to exit inserting. Shift-z shift-z (twice) to save and exit or Ctrl-z to exit without saving.
  5. Then, to make sure this is working, check your Drupal status report which shows the cron run time.

Enable cron using Drupal-contributed modules

If this example and that page daunted you, test Drupal's contributed modules (like Ultimate Cron.)

Help improve this page

Page status: Needs review

You can: