1. Verwenden Sie Swooles Tick, um alle 3 Sekunden die zu sendenden Informationen abzufragen. Der Timer läuft jedoch nicht mehr wird gestartet, wenn der Arbeitsprozess gestartet wird
<code>function onWorkerStart(swoole_server $serv, $worker_id) { $this->loger->write_log('info',"Work_id " . $worker_id . " start \n"); //如果当前运行的进程是task进程 if($worker_id < $serv->setting['worker_num']) { //开始执行任务 $serv->task($worker_id); } //添加定时器 只在第一个worker启动时创建一个定时器 来定时检索有没有要推送的消息 if($worker_id == 0) { //创建定时器 $timer = $serv->tick(3000,function ($timer_id){ $db = new DBO(config_item('mall_db_config')); //获取所有未发送的推送消息 $query_param = array('limit'=>100,'order'=>'createon asc','where'=>'msg_status = 0'); $msgs = $db->select('t_msg_push', array('id','mall_id','member_id','vpl','in_time','out_time','park_code', 'pay_points','park_duration','residual_points','msg_type'), $query_param ); if(!empty($msgs)) { push_msg($msgs,$db); } else { simple_log('No message to send.'); } //关闭数据库连接 $db->close(); }); } }</code>
1. Verwenden Sie Swooles Tick, um alle 3 Sekunden die zu sendenden Informationen abzufragen. Der Timer läuft jedoch nicht mehr wird gestartet, wenn der Arbeitsprozess gestartet wird
<code>function onWorkerStart(swoole_server $serv, $worker_id) { $this->loger->write_log('info',"Work_id " . $worker_id . " start \n"); //如果当前运行的进程是task进程 if($worker_id < $serv->setting['worker_num']) { //开始执行任务 $serv->task($worker_id); } //添加定时器 只在第一个worker启动时创建一个定时器 来定时检索有没有要推送的消息 if($worker_id == 0) { //创建定时器 $timer = $serv->tick(3000,function ($timer_id){ $db = new DBO(config_item('mall_db_config')); //获取所有未发送的推送消息 $query_param = array('limit'=>100,'order'=>'createon asc','where'=>'msg_status = 0'); $msgs = $db->select('t_msg_push', array('id','mall_id','member_id','vpl','in_time','out_time','park_code', 'pay_points','park_duration','residual_points','msg_type'), $query_param ); if(!empty($msgs)) { push_msg($msgs,$db); } else { simple_log('No message to send.'); } //关闭数据库连接 $db->close(); }); } }</code>