巧妙利用定时任务执行精准时间动作

    众所周知,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秒,这样保证我们定时任务的执行。

 

posted @ 2020-05-21 20:21  龙卷风之殇  阅读(463)  评论(0)    收藏  举报