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

 

相关文章:

  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2021-06-22
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2021-10-27
  • 2022-12-23
相关资源
相似解决方案