CRON-ological Perfection: How Drupal’s Cron Runs Scheduled Tasks on Your Website Automatically

Feb 12 2025

Authored by Nadiia Nykolaichuk and Dave Bezuidenhout.

 

Your Drupal website is equipped with powerful tools, akin to a team of efficient and reliable assistants. Among them, Cron stands out for its unparalleled time-management skills. It expertly handles scheduled website tasks, ensuring smooth operations while saving you valuable time. Even its name is reminiscent of “Chronos,” the Greek personification of time. In this article, we’re delighted to demystify Drupal’s Cron system.

 

Cron’s primary mission is to run scheduled tasks automatically, freeing you from repetitive manual work. This ensures your website operates smoothly, as critical processes are executed with precision. Tasks run in a perfect chronological — or should we say “CRON-ological” — order. Let’s explore how this automatic task runner functions, the processes it can automate, and the ways to configure it on a Drupal website.

Getting acquainted with Drupal’s Cron system

The key things to understand about Drupal’s automated task runner

Imagine your website having an automated "to-do list." At regular intervals, Cron reviews its assigned tasks and executes them seamlessly—no manual intervention required. It’s like a virtual assistant that takes care of routine jobs so you can focus on more creative aspects of your site.

 

For example, it might send notifications, clear the caches, check for updates, update search indexes, publish content, and so on. These routine tasks help keep your site fast, accurate, and up to date.

 

Many of Drupal core’s maintenance processes rely on Cron. Additionally, you can extend its functionality by assigning specific periodic tasks through contributed or custom modules, server configurations, or command-line tools.

 

Out of the box, Drupal includes the Automated Cron module, providing a simple interface for Cron management. For more complex needs, modules like Ultimate Cron offer advanced control and customization. Furthermore, extremely granular settings at an advanced level can be made programmatically.

Inspired by Unix

The concept of scheduled, recurring tasks originates from the Unix Cron system. Unix, a family of operating systems developed in the 1970s, has inspired many modern systems like Linux, macOS, and even aspects of Windows. As Linux powers most web servers, Unix’s legacy remains foundational in today’s computing landscape.

Examples of tasks performed by Drupal Cron

Cron automates a wide range of tasks on your website, including (but not limited to):

  • Sending scheduled emails or notifications
  • Updating search indexes for new or modified content
  • Clearing caches to display the latest content to users
  • Checking for module updates and notifying administrators about them
  • Performing database maintenance (like clearing logs or optimizing tables)
  • Scheduling content for publishing or unpublishing
  • Running backup scripts to ensure data safety
  • Removing temporary files

Examples of modules relying on Cron

Among modules that use Cron, there are big names that belong to the top ten most popular Drupal modules of all time. Often, you’ll hear about a module’s capabilities without realizing that its seamless performance rests on the dependable shoulders of the hardworking Cron.

 

Let’s see some examples of famous modules relying on Cron:
 

  • Scheduler. You might have seen our guide to scheduling your content for future publishing (if not, it’s never too late). The Scheduler module enables you to schedule content to be published and/or unpublished at the specified dates and times. It uses its own feature called Lightweight Cron. What makes it great is that it runs only Scheduler-specific tasks often enough to provide content publishing accuracy. At the same time, your website doesn’t have to be overloaded by running Cron’s entire “to-do list” too often.
     

Setting the date and time for publishing/unpublishing content with Scheduler
 

  • Pathauto. We also walked you through the automatic generation of page URLs based on configurable patterns with the help of the Pathauto module. Cron is a great assistant for Pathuto when additional modules like Pathauto Update are used. This module ensures the automatic regeneration of path aliases when values change. Thanks to Cron, this happens automatically whenever you create, update, or delete content.
  • Automatic Updates. Automatic Updates, the ground-breaking innovation in Drupal, is currently in the final stages of its development. It’s going to offer users a very handy option — an unattended mode. Although with certain limitations and precautions, it should be possible to let Cron trigger website updates regularly, without human intervention.
     
unattended-automatic-updates-in-drupal

Unattended mode settings in Automatic Updates
 

  • Content Moderation. This Drupal core module manages Drupal’s content workflow and moderation states (like Draft, Published, Archived, or others). Cron is used to transition content between different states at set intervals or based on scheduled changes.
  • Webform. The most robust and famous module for creating and managing forms uses Cron, too. Cron helps process form submissions, send notifications, or manage any post-submission tasks like exporting data or triggering workflows.
  • Search API. The Search API module is known to provide a flexible framework for creating search functionality on Drupal sites. It can rely on Cron to automatically update the search index, ensuring that content is searchable as it changes.
  • Devel. The Devel module provides developer tools for debugging, testing, and performance analysis. Devel uses Cron for tasks like generating dummy content, running performance tests, and clearing caches, which are useful during development.
  • Mailchimp. A great example is how Cron cooperates with the Mailchimp module. The module’s mission is email marketing and subscription management. Cron is used to synchronize subscriber data, send scheduled campaigns, and handle email lists automatically at set intervals.

A quick cheat sheet on Cron’s key concepts

Cron job. In Cron’s terminology, tasks are officially called jobs. A cron job is a scheduled task that runs automatically at specified intervals.

 

Crontab (short for “Cron table”). Crontab is a configuration file that contains a list of cron jobs and their schedules. You edit a Crontab file to set up, modify, or delete cron jobs.

 

Cron expression. It is a string that defines the schedule for a cron job. It specifies the exact times, dates, or intervals when a job should run. The expression consists of five (or sometimes six) fields representing minutes, hours, days of the month, months, days of the week, and optionally, the year. For example, 0 0 * * * means “run at midnight every day.”

 

Cron Daemon (Cron Service). It is the background process that runs on a Unix-like operating system, responsible for executing scheduled tasks. It continuously checks the Crontab files for tasks that need to be executed at their scheduled times and then runs them automatically.

 

Cron timing. This refers to how often a job is scheduled to run, determined by the Cron expression. Timing can range from every minute (* * * * *) to specific times of day, days of the week, or months.

The right balance: how often should Cron run?

For sites with frequent updates, like news or e-commerce, setting Cron to run hourly or even more frequently may be helpful to keep content current. For less active sites, a daily schedule might be enough.

 

Running Cron too frequently can slow down your site, especially if the tasks are resource-heavy. Strike a balance — run it often enough to keep things updated, but not so often that it impacts performance.

 

In addition, for larger and high-traffic websites, there are additional tweaks for efficiently running cron tasks without negatively impacting performance:

 

  • using external cron jobs on the server
  • breaking large tasks into smaller “queued” tasks
  • scheduling high-priority tasks at different times than your other tasks

The ways Drupal’s Cron can be triggered

  1. Setting up a cron job on the website’s server. A cron job is configured directly on the server to run the cron script at regular intervals. Some managed Drupal hosting providers (like Pantheon) include built-in cron scheduling, so you don’t need to set it up yourself.

    Pantheon automatically triggers cron every hour. It is not customizable, but additional cron triggers can be set up using external services (see below), including using your own custom service along with Pantheon’s command line connection (Terminus). https://docs.pantheon.io/drupal-cron#pantheon-cron-execution

    Acquia’s cron service is set up in the Cloud Platform administration area. Acquia provides a specific cron script that can be used to trigger the website’s Cron functions: /usr/local/bin/cron-wrapper.sh [site].[env] http://[site_URL]  
     

Acquia's cron service triggers website Cron functions via a specific script

2. Using an external service. External services like Pingdom, cron-job.org, or similar tools can call the Drupal cron script on a preset schedule. 

Any Application Performance Monitoring (APM) “synthetic”, such as those provided by New Relic, Pingdom, or Datadog, should provide a way to configure what is essentially a ping test — the periodic calling of a specific website URL to check for the appropriate response. 

The URL can be set to Drupal’s cron webhook URL, which can be found on the Cron administration page at admin/config/system/cron. This URL should not be publicized since it can trigger load on your website’s server, and in the wrong hands could be used to place excessive load on your website.

 

Many web hosts include monitoring systems like New Relic. This example shows how a “ping monitor” can be created that will automatically send a request on the set schedule, and this can be used to call the Drupal Cron URL.
 

Example of a ping monitor triggering Drupal Cron via New Relic

3. Using website requests (traffic). Drupal’s built-in Automated Cron runs when the website receives a request after the set Cron interval. This method is dependent on website traffic, so it is an easy way to get Cron running without setting up a Cron trigger outside of the website. 

One challenge is that if your site has no visitors, Cron won’t run, as it relies on user requests to trigger its execution. The first request after the Cron interval may also be slowed while Cron tasks are processed, causing a long page load time for that request. Additionally, if there is front-end caching (like Varnish), those requests might not hit the CMS, making it a potentially unreliable way of triggering Cron.

The ways Drupal’s Cron can be configured

Via the main admin interface

Drupal’s built-in Automated Cron module provides a pretty intuitive and lightweight interface, making it accessible to all users. Automated Cron used to be called “Poormans Cron” because it was for people who did not have access to set up cron jobs on the server.

 

By going to Configuration > System > Cron, you can configure how frequently Cron should run. The default is three hours.

 

In addition, there is an option that is selected by default to keep a detailed log of cron jobs. You will then be able to monitor Cron’s activity in the usual place where Drupal keeps logs of all that’s happening on the website — Reports > Recent log messages. 

 

built-in-cron-settings-drupal-intervals-and-logging

The built-in Cron settings in Drupal: the intervals and the logging

 

On Cron’s configuration page, you can also see when Cron’s last run was. Another useful option is to push the button to run Cron immediately. This may come in handy if you need some tasks to be executed but don’t want to wait for Cron’s next officially scheduled run.

 

built-in-cron-settings-drupal-on-demand-running-and-last-run-information

The built-in Cron settings in Drupal: on-demand running and the last run information

Via the Ultimate Cron contributed module

Large or complex sites might benefit from using the Ultimate Cron contributed module beyond the built-in Cron system. 

 

Parallel execution. Ultimate Cron can run multiple tasks in parallel rather than sequentially. A long task won’t hold up the shorter ones. In contrast, the built-in Cron system runs all tasks in a single sequence, which can be slower.

 

Configurable rules. The module uses configurable rules to manage the order and frequency of tasks, so you can prioritize important tasks over less critical ones.

 

Smart website load management. Ultimate Cron monitors the server’s workload and adjusts the timing of tasks, running them only when the server can handle them efficiently. This reduces the risk of slowing down the site during busy times.

 

Detailed settings in the user interface. With this module installed, you get a more detailed Cron settings page with the list of all cron jobs, the modules that use them, their schedule, last run, duration, and status. You can run, edit, view logs for, or delete the jobs.

 

The page with cron jobs in the Ultimate Cron’s module interface

 

There are additional tabs for more advanced and intricate Cron settings. Among them are:

 

  • Queue. It manages how tasks are queued up and processed.
  • Launcher. It configures how cron jobs are launched.
  • Logger. It keeps detailed logs of each Cron run.
  • Scheduler. It allows precise scheduling for each task.
     

Additional settings in the Ultimate Cron’s module interface

Drush commands and queue runners. In addition to the user interface, Ultimate Cron allows for leveraging specific:

  • Drush commands
  • queue runners (tools designed to handle long-running tasks efficiently by processing them in smaller, manageable chunks)

Ultimate Cron provides its own set of Drush commands tailored to its advanced features. This lets you manage complex tasks, like running long processes or batch jobs, efficiently in the background. 

Via the hook_cron function

This function allows developers to schedule custom tasks, extending Cron's functionality with module-specific actions. It’s widely used in contributed and custom modules that rely on Cron. 

 

They implement the function to define their periodic tasks. When Cron is triggered, Drupal looks for all active modules that implement this function and executes the code for each one. This executes all tasks scheduled by various modules.

Via the command line

Advanced users, like site administrators and developers, can also manage Cron using the command line. They can manually trigger Cron (the “drush cron” command), set up specific schedules, or check logs. The commands used for Cron are part of the core Drush toolkit.

 

This approach offers more flexibility, allowing Cron to run on demand or be set with highly customized schedules. It’s ideal for sites with unique timing requirements.

Via external cron jobs on the server

By configuring external cron jobs directly on the server, typically through the Crontab file, administrators can set precise, independent schedules. Using Cron expressions (like 0 2 * * * for daily at 2 a.m.), these external jobs allow Drupal’s Cron to run without relying on site traffic, ensuring tasks are executed reliably on high-traffic sites.

Via the settings.php file

In Drupal’s settings.php file, developers can control Cron scheduling programmatically. Fine-tuned intervals and custom settings that are more tailored than what the admin interface allows. This option is particularly useful when more specific control is needed for complex sites.

Final thoughts

Cron does a great job — or, based on Cron’s terminology, we can say it does multiple great jobs for your website. Embrace Cron’s potential to streamline your workflows, automate critical site functions, and ensure your Drupal website performs at its best. You can customize Cron to suit your website’s needs and assign it a variety of tasks. If you ever need expert guidance from a professional Drupal development team, don’t hesitate to reach out.

 

 

Learn from us
Sign up and receive our monthly insights directly in your inbox!

Subcribe to newsletter (no spam)

Fields