Drupal hook: hook_cron

Printer-friendly versionSend to a DeveloperPDF version

You've just published a Drupal website and people find it very useful. So, they started signing up with your website and its really very good traffic now. You have planned to implement some features and you want to let know about to all the members of the site. There are two ways: you send e-mails to individuals by using their contact form or implement a system with which you create a node and the site itself sends e-mails. How about sending the e-mails at specific period of time? ohh.. yeah. that's great. Drupal's hook_run makes it happen. Since, there are more features to come, you want to do this every time you have something new to let others know about, you would use hook_cron, which performs specific tasks assigned to it periodically. With hook_cron, modules can schedule their specific tasks to be executed periodically. You should schedule all those jobs in hook_cron which are time consuming and use lots of resources.
So, here is the way you can implement hook_cron

<?php
/**
* Implementation of hook_cron
*
* @author Drupal Developer
*/
function mynode_cron() {
 
$r__result = db_query("SELECT uid FROM {users}");
  while (
$om__user = db_fetch_object($r__result)) {
   
send_mail_to_user($om__user->uid);
  }
}
?>

Syndicate content

Recent comments

toolbar powered by www.mit3xxx.de