Issue
I need to schedule tasks for my Drupal site.
Resolution
Scheduling tasks
The steps that you'll take to configure applications to run at scheduled times on your server vary based on your server's operating system.
With Mac, Linux and Unix servers, you manage scheduled tasks by creating and editing crontabs that execute cron jobs at specified intervals.
Crontab syntax
A crontab consists of five placeholders, or numbers, and a command to be executed. The numbers indicate how often it should run:
* * * * * [command]
The five asterisks represent the Cron time string the cron uses to determine the schedule to execute [command]
. For more information about the cron time string, including how to format the string to create time intervals, see Cron time string format.
If you want to save the results of a scheduled task to a file, use a crontab similar to the following:
* * * * * [command] >> [path]/[logfile]
where [path]
and [logfile]
are the path and name of the log file, respectively.
Example
The following example configures the crontab to run a Drupal cron job every five minutes, with the task of running the Drupal cron
directive.
- Open a terminal window on your computer and enter the following command to edit your crontab - this will invoke your default editor (usually a flavor of vi):
crontab -e
- Enter the following scheduled task (where
[docroot_path]
is your server's docroot, and[site_URL]
is your website's URL):*/5 * * * * drush --root=[docroot_path] --uri=[site_URL] cron
To confirm that the crontab is working, set your scheduled task to run at five-minute intervals, and then examine the Recent log messages page of your localhost installation in the administration menu at Reports > Recent log messages (http://[site_URL]/admin/reports/dblog
) after 10 to 15 minutes.You can also use the command crontab -l
to show the cron entries.
For more information about configuring cron jobs, see Configuring cron jobs at drupal.org.
Windows
In Windows, use Scheduled Tasks or Task Scheduler to run any scheduled tasks or scripts at regular intervals for your website.
Create any new scheduled tasks based on the following items:
- For the scheduled task's command to run, enter the path and filename for your installed web browser, followed by the command you want to run in double quotation marks. For example, if you installed Acquia Drupal using the Acquia Dev Desktop and its standard ports, and you wanted to run
cron.php
for your website, the address would behttp://localhost:8082/cron.php.
for Drupal 6. In later Drupal versions, go tohttp://[site_url]/admin/reports/status/run-cron
. - If you configure the scheduled task to run after relatively long intervals, you can set the start time to a minute later than the current time to be able to check right away that it is working correctly.
To confirm that the scheduled task is working, set your task to run at five-minute intervals, and then examine the Recent log messages page of your localhost installation at Reports > Recent log messages (http://[site_URL]/admin/reports/dblog
) after 10 to 15 minutes.
For information about how to create scheduled tasks in Windows, see the Help file for your installed version of Windows.
Scheduling cron on your website
Drupal cron is responsible for running periodic website maintenance tasks, including checking for updates and indexing content for a search, and like Unix cron, you can configure it to run on a regular schedule. Because Drupal cron is an application, you can configure it to run on a schedule determined by your server's operating system or hosting environment.
Drupal 7 and Drupal 8
To manage your Drupal 7 and/or Drupal 8-based website's cron settings, go to Configuration > Cron (http://[site_URL]/admin/config/system/cron
). The Cron page allows you to run cron immediately or on a regular schedule.
Drupal 6
Drupal 6-based websites can't start their own cron jobs. Websites need an outside service to visit the URL http://[site_URL]/cron.php
at regular intervals to initiate these maintenance tasks. For live, production websites, there are various cron services available, including Acquia's subscriber cron service.
If you've installed Drupal onto your computer (localhost) or another IP address not accessible from the public Internet, you'll need to configure cron jobs to run from your own computer.
Cause
As a part of your Drupal website's normal operations, you might want to perform certain self-maintenance tasks on a regular basis (including running cron on your website). These tasks can include, but are not limited to, updating database tables, exchanging information with the Acquia Insight, and sending information to third-party services.