首页决定了一个核心概念。clearTimer只能清除当前进程的定时器。服务器代码如下:serv=newswoole_server("0.0.0.0",9501);$this->serv->set(['worker_num'=>8,'daemonize'=>false,]);$this->serv->on('开始',[$this,'onStart']);$this->serv->on('Connect',[$this,'onConnect']);$this->serv->on('接收',[$this,'onReceive']);$this->serv->on('关闭',[$this,'onClose']);$this->serv->start();}publicfunctiononStart($serv){$this->echoStr("ServerStarting");$this->timer=$serv->tick(1000,function(){$this->echoStr("timerwaiting");});//$this->timer=swoole_timer_tick(1000,function(){//});}publicfunctiononConnect($serv,$fd,$from_id){//swoole_timer_c李尔($this->timer);$serv->clearTimer($this->timer);$this->echoStr("正在连接!清除定时器!");//$serv->send($fd,"你好{$fd}!");}publicfunctiononReceive(swoole_server$serv,$fd,$from_id,$data){$this->echoStr("GetMessageFromClient{$fd}:{$data}");$serv->发送($fd,$data);}publicfunctiononClose($serv,$fd,$from_id){$this->echoStr("Client{$fd}关闭连接");}publicfunctionechoStr($msg){echo'['.日期('Y-m-dH:i:s')。']:'。$味精。PHP_EOL;}}//启动服务器启动服务器$server=newServer();Intention服务器启动后,会循环输出“timerwaiting”,客户端连接后定时器会被清除。但是在Master进程的主线程中调用了onStart事件,在work进程中回调了onConnect事件,不属于同一个进程,所以连接后客户端会提示:PHPWarning:SwooleServer::clearTimer():notimer...
