CRON tasks

Last modified: August 31, 2008 - 15:03

Configuring cron is an extremely important task in your Drupal website setup. Search module indexing of your website's content, aggregator module's retrieval of feeds, ping module's notification of other sites of updates, and system module's routine maintenance tasks, such as pruning of logs, all depend a properly configured cron job.

Following is a brief description of cron jobs, but for more detailed information about configuring cron for Drupal, see Configuring cron jobs.

What is a cron job?

Many Drupal modules have tasks that have to take place from time to time. Think of cron as the tolling of a bell, letting Drupal know that it should perform the appropriate tasks.

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 service or even from your own desktop.

For your Drupal site, what actually happens is that the cron job triggers an invisible visit to http://www.example.com/cron.php – which, in turn, executes tasks on behalf of installed modules.

The cron command

The following example crontab command will activate the cron tasks automatically on the hour:

0 * * * * wget -O - -q -t 1 http://www.example.com/cron.php

In the above sample, the 0 * * * * represents when the task should happen. The first figure represents minutes – in this case, on the "zero" minute, or top of the hour. (If the number were, say, 10, then the action would take place at 10 minutes past the hour.) The other figures represent, respectively, hour, day, month and year. A * is a wildcard, meaning "every time."

The rest of the line basically tells the server to "ping" the url http://www.example.com/cron.php.

Here is a diagram of the general crontab syntax, for illustration:

# +---------------- minute (0 - 59)
# |  +------------- hour (0 - 23)
# |  |  +---------- day of month (1 - 31)
# |  |  |  +------- month (1 - 12)
# |  |  |  |  +---- day of week (0 - 7) (Sunday=0 or 7)
# |  |  |  |  |
  *  *  *  *  *  command to be executed

Thus, the cron command example above means "ping http://www.example.com/cron.php at the zero minute on every hour of every day of every month of every year."

Configuring cron

There are many ways to configure a cron job. If you have full access to crontab features, you should be able to simply paste in the above example command – be sure to replace "http://www.example.com" with your own web domain or docroot.

If you're on shared hosting, you should be able to find cron job configuration somewhere in your hosting control panel. Some hosts even have cron "wizards" that walk you through the cron configuration, making it much easier if cron is new to you. On a Windows system you can accomplish the same thing with scheduled tasks to launch Internet Explorer pointed to the URL.

Still need help? There is a lot more information about configuring cron for Drupal at Configuring cron jobs.

 
 

Drupal is a registered trademark of Dries Buytaert.