4

Im using the cronapi coming with Elysia cron module and here is my code :

function MYMODULE_cronapi($op, $job = NULL) {
  $items['example_news_cron'] = array(
    'description' => 'Send mail with news',
    'rule' => '*/5 * * * *', // Every 5 minutes
    'callback' => 'example_news_fetch'
  );
  return $items;
}
function example_news_fetch() {
  // Do something here 
}

the cron works only when I run it manually in the admin section(Elysia cron configuration), but I need it to be runing every some specific periode !

Is there some configuration missing, or system requirements

  • 1
    How do you poke your cron tasks? Drush and entry in system's crontab? – Mołot Dec 27 '13 at 8:30
  • In fact I don't know what you mean your question "Drush and entry in system's crontab?" I know Drush and it's installed, but what is "entry" ? and what mean that Drush and entry are in system's crontab ? – Boussetta moez Dec 27 '13 at 8:39
  • I think you answered me all right... And arpitr provided pretty good answer :) You need to initiate cron tasks somehow, it will not happen automagically. OK, it may, but for that you need to have enough traffic on your site and it used to be called "poor man's cron", so better not to try unless you have to. – Mołot Dec 27 '13 at 8:43
7

As you said "the cron works only when I run it manually in the admin section (Elysia cron configuration), but I need it to be runing every some specific periode !", it tells your codes are working fine.

By default Drupal cron runs when site is accessed and it evaluates when was the last time cron ran, so if the prescribed time is passed cron will run again, but for that site needs to be accessed, so you have a task which is supposed to run at fix period, you can not wait for Drupal site to be accessed by some one, instead you need to set a crontab on your server which means your server will ping your cron.php at the scheduled time.

Check How to setup cron tab on Linux based system or as an alternate option you can use drush while setting up cron tab (see: cron.html).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.