不用定时任务的情况下, 百度了一下发现是有这么个方法,原文请戳:https://www.cnblogs.com/i6010/articles/4875030.html
public function timing($time){ ignore_user_abort(TRUE); #设定关闭浏览器也执行程序 set_time_limit(0); #设定响应时间不限制,默认为30秒 $count = 0; while (TRUE) { sleep($time); #每$time秒钟执行一次 $wx = new Weixin(); $accessToken = $wx->accessToken(); $userId = session("userInfo.userid"); try{
#执行代码
#停止条件 if ($counts==3) { break; } }catch (Exception $e){ die($e->getMessage()); } } }