實現案例如下:
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() 函數來延遲代碼執行也是可以的。
需要注意的是,必須要訪問一次接口才能執行,如果想自動執行,就要做定時任務跑腳本了。