8 core.api.php hook_cron()
4.6 core.php hook_cron()
4.7 core.php hook_cron()
5 core.php hook_cron()
6 core.php hook_cron()
7 system.api.php hook_cron()

Perform periodic actions.

Modules that require some commands to be executed periodically can implement hook_cron(). The engine will then call the hook whenever a cron run happens, as defined by the administrator. Typical tasks managed by hook_cron() are database maintenance, backups, recalculation of settings or parameters, automated mailing, and retrieving remote data.

Short-running or non-resource-intensive tasks can be executed directly in the hook_cron() implementation.

Long-running tasks and tasks that could time out, such as retrieving remote data, sending email, and intensive file tasks, should use the queue API instead of executing the tasks directly. To do this, first define one or more queues via hook_cron_queue_info(). Then, add items that need to be processed to the defined queues.

Related topics

16 functions implement hook_cron()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_cron in modules/aggregator/aggregator.module
Implements hook_cron().
common_test_cron in modules/simpletest/tests/common_test.module
Implements hook_cron().
common_test_cron_helper_cron in modules/simpletest/tests/common_test_cron_helper.module
Implements hook_cron().
dblog_cron in modules/dblog/dblog.module
Implements hook_cron().
field_cron in modules/field/field.module
Implements hook_cron().

... See full list

1 invocation of hook_cron()
drupal_cron_run in includes/common.inc
Executes a cron run when called.


modules/system/system.api.php, line 575
Hooks provided by Drupal core and the System module.


function hook_cron() {
  // Short-running operation example, not using a queue:
  // Delete all expired records since the last cron run.
  $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
    ->condition('expires', $expires, '>=')
  variable_set('mymodule_cron_last_run', REQUEST_TIME);

  // Long-running operation example, leveraging a queue:
  // Fetch feeds from other sites.
  $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array(
    ':time' => REQUEST_TIME,
  $queue = DrupalQueue::get('aggregator_feeds');
  foreach ($result as $feed) {


Unlike many Drupal hooks, DrupalQueueInterface::createItem() only accepts a single argument, so $queue->createItem($arg1, $arg2); will generate notices if the callback needs more than one argument, (and you loss these extra parameters).

You can always use an array or object containing structured data to pass multiple parameters within the $data parameter. That's what the example with the aggregator module demonstrates.

Este funcion(el hook) se ejecutara cada vez que se ejecute el cron,

Un ejemplo:
In standar.module

function standar_cron()
//  Este mensaje se registrara cuando se ejecute el cron
    //  Y lo pueden ver en Informes->Mensajes recientes del registro
watchdog('encron','esta funcion se ejecuto cuando se ejecuto el cron');