我从之前的php cronjob文件中获得了默认代码,但它设置了24小时cronjob。如何将其设置为1小时(60分钟)cronjob?
PHP cronjob:
$diff = array();
function date_diff($d1, $d2){
$d1 = (is_string($d1) ? strtotime($d1) : $d1);
$d2 = (is_string($d2) ? strtotime($d2) : $d2);
$diff_secs = abs($d1 - $d2);
$base_year = min(date("Y", $d1), date("Y", $d2));
$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
return array(
"years" => date("Y", $diff) - $base_year,
"months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
"months" => date("n", $diff) - 1,
"days_total" => floor($diff_secs / (3600 * 24)),
"days" => date("j", $diff) - 1,
"hours_total" => floor($diff_secs / 3600),
"hours" => date("G", $diff),
"minutes_total" => floor($diff_secs / 60),
"minutes" => (int) date("i", $diff),
"seconds_total" => $diff_secs,
"seconds" => (int) date("s", $diff)
);
}
$timest=mysql_result($res,$i,"timestamp");
$timenow = time();
$diffArray = date_diff($timest,$timenow);
// needs attention ########################
if($diffArray['hours']>=1){
$yes = true;
mysql_query("UPDATE services SET moneyback='$custId' WHERE customer='$custId'") or die(mysql_error());
fwrite($log,$custId."money back void");
fclose($log);
exit;
}
答案 0 :(得分:2)
这不起作用吗?
if($diffArray['minutes_total']>=60){
更改后您还需要设置cron作业。 为此,您需要通过编辑corntab来配置您的玉米棒
在命令行中解决该问题
crontab -e
然后将值更改为
0 * * * * wget -O - -q -t 1 http://mysite/cron.php
将退出值(可能是)从0 0 * * *
更改为0 * * * *