hook_cron

  1. drupal
    1. 5
    2. 8 system.api.php
    3. 6
    4. 7 system.api.php
Versions
5 – 7 hook_cron()

Perform periodic actions.

Modules that require to schedule some commands to be executed at regular intervals can implement hook_cron(). The engine will then call the hook at the appropriate intervals defined by the administrator. This interface is particularly handy to implement timers or to automate certain tasks. Database maintenance, recalculation of settings or parameters, and automatic mailings are good candidates for cron tasks.

Return value

None.

This hook will only be called if cron.php is run (e.g. by crontab).

Related topics

Code

documentation/developer/hooks/core.php, line 152

<?php
function hook_cron() {
  $result = db_query('SELECT * FROM {site} WHERE checked = 0 OR checked
    + refresh < %d', time());

  while ($site = db_fetch_array($result)) {
    cloud_update($site);
  }
}
?>