Drupal7 中的 CronJob 不是 运行
CronJob not Running in automatically Drupal7
我们在项目中使用 Drupal。我们计划使用 cronjob 发送邮件功能。我创建了自定义模块,还创建了 hello_cronapi() 挂钩函数。我的 cron 名称在管理面板中查看如下路径。
主页 » 管理 » 配置 » 系统
在管理面板的 cronsetting 页面中,选中 Force 运行 按钮 cron is 运行ning。我已将我的 cronjob 运行 每 15 分钟设置一次,但它不是自动 运行(每 15 分钟)
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;
}
函数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;
}
上面的cronjob是创建一个文件并将内容放入文件中。但是文件没有创建
Drupal cron 不会自动 运行,它们会在用户点击您的页面时 运行。如果你想要一个预定的 运行,你必须在你的网络服务器上设置一个 cron 任务。
我们在项目中使用 Drupal。我们计划使用 cronjob 发送邮件功能。我创建了自定义模块,还创建了 hello_cronapi() 挂钩函数。我的 cron 名称在管理面板中查看如下路径。
主页 » 管理 » 配置 » 系统
在管理面板的 cronsetting 页面中,选中 Force 运行 按钮 cron is 运行ning。我已将我的 cronjob 运行 每 15 分钟设置一次,但它不是自动 运行(每 15 分钟)
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;
}
函数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;
}
上面的cronjob是创建一个文件并将内容放入文件中。但是文件没有创建
Drupal cron 不会自动 运行,它们会在用户点击您的页面时 运行。如果你想要一个预定的 运行,你必须在你的网络服务器上设置一个 cron 任务。