Selvamani P
Selvamani P

Reputation: 7313

CronJob not Running in automatically Drupal7

We are Using Drupal in out project. Send mail Functionality we are planned to use cronjob. I have created the custom module and also created the hello_cronapi() hook function. My cron name is viewed the admin panel like below path.

Home » Administration » Configuration » System

In Admin panel cronsetting page when check the Force run button cron is running. I have set my cronjob run to every 15 min but it's not run automatically(Every 15 min)

function hello_cronapi($op, $job = NULL){
   $items['example_sendmail_cron'] = array(
    'description' => 'Send mail with news',
    'rule' => '* * * * *', // Every 5 minutes
  );

  $items['example_news_cron'] = array(
    'description' => 'Send mail with news',
    'rule' => '*/15 * * * *', // Every 5 minutes
    // i must call: example_news_fetch('all')
    'callback' => 'example_news_cron',
    'arguments' => array('all'),
  );
    return $items;

}

function example_sendmail_cron() {

    echo "Company"; 
    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
    $txt = "John Doe\n";
    fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
    $txt = "Jane Doe\n";
    fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
    fclose($myfile);

    exit;
}
function example_news_cron() {

    echo "Company"; 
    $myfile = fopen("newfile2.txt", "w") or die("Unable to open file!");
    $txt = "John Doe\n";
    fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
    $txt = "Jane Doe\n";
    fwrite($myfile, $txt, FILE_APPEND | LOCK_EX);
    fclose($myfile);

    exit;
}

In above cronjob is create a file and put the content in the file. But the files is not create

Upvotes: 0

Views: 969

Answers (1)

Geoffray Warnants
Geoffray Warnants

Reputation: 82

Drupal crons are not run automatically, they are run when a user hits on your pages. If you want a scheduled run, you'll have to setup a cron task on your webserver.

More explanation here : https://www.drupal.org/docs/7/setting-up-cron-for-drupal/configuring-cron-jobs-using-the-cron-command

Upvotes: 1

Related Questions