'Cron Example: Trigger cron.php', 'page callback' => 'drupal_get_form', 'page arguments' => array('cron_example_form'), 'access arguments' => array('access content'), ); return $items; } /** * The form to provide a link to cron.php. */ function cron_example_form() { $form['intro'] = array( '#value' => t('Use this page to trigger a cron run. When you click the link, cron_example.module will set a status message and return to this page.'), ); $form['cron_trigger'] = array( '#type' => 'item', '#value' => l(t('Trigger Cron'), 'admin/reports/status/run-cron', array('query' => array('destination' => 'cron_example'))), ); return $form; } /** * Implements hook_cron() */ function cron_example_cron() { // This module has not actually implemented a configuration page. // So, there isn't a variable in the variables table to get. // Therefore, in our situation, the value returned will be 1. // But, many modules will need to provide this functionality // to ensure that they don't run more frequently than desired. $frequency = variable_get('cron_example_frequency', 1); // In our case, this will set the interval to daily. $interval = 60 * 60 * 24 * $frequency; // As with above, we are not actually setting the below variable anywhere. // Again, many modules will need to do this. // So, somewhere in their code they would need to do: // variable_set('cron_example_last_check', time()) // using an appropriate name for the variable. // In our case, since we don't have an variable to get, the value // returned will be 0. Therefore, the current time - 0 will always be // greater than the interval determined above. if (time() - variable_get('cron_example_last_check', 0) > $interval) { // This is a silly example of a cron job. // It just makes it obvious that the job has run without // making any changes to your database. drupal_set_message(t('cron_example_cron ran!'), 'status'); } } /** * @} End of "defgroup cron_example". */