php实现延时执行后面代码

实现案例如下:

header('Content-Type:application/json; charset=utf-8');
$info=array();
$info['result']="0";
$info['msg']="Success";
$info['data']=array("order"=>$return['order']);
echo json_encode($info);
fastcgi_finish_request();  // 把数据先返回给App

time_sleep_until(time()+20); // 在20秒后执行后面代码
$ceshi['id'] = 007;
$ceshi['time'] = time();
M("ceshi")->add($ceshi);

当然用sleep() 函数来延迟代码执行也是可以的。

需要注意的是,必须要访问一次接口才能执行,如果想自动执行,就要做定时任务跑脚本了。

原文地址:https://www.cnblogs.com/boats/p/7323748.html