巧妙利用定时任务执行精准时间动作
众所周知,Linux的定时任务的最小单位是 以分为单位的,如果我们现在要执行一个秒级别的的定时任务,如何执行呢?
如果我们以常规的定时任务执行,可能会跳过我们的定时任务。二种解决方式:
1.使用superviror
我其他文章讲过
2.定时任务crontab 执行
Util_Log::write(Util_Log::LOG_TYPE_INFO,'========项目选标定时任务------开启=========');
$model = new Admin_BaseModel('project_info_view');
$where = [
'status' =>2,
];
$res = $model->fetchAll($where);
$now = time();
if(!empty($res)){
foreach ($res as $item){
$deadline_time_delay = $now - strtotime($item['deadline']);
if($deadline_time_delay>=0 && $deadline_time_delay<60){
# do something ……
}
}
}
通过上面的例子,我们可以将误差设定到60秒,这样保证我们定时任务的执行。
龙卷风之殇

浙公网安备 33010602011771号