日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

swoole 清除定时器提示no timer

發布時間:2024/1/17 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 swoole 清除定时器提示no timer 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首頁確定一個核心概念

clearTimer僅可清除當前進程的定時器

server代碼如下:

<?php class Server {private $serv;private $timer;public function __construct(){$this->serv = new swoole_server("0.0.0.0", 9501);$this->serv->set(['worker_num' => 8,'daemonize' => false,]);$this->serv->on('Start', [$this, 'onStart']);$this->serv->on('Connect', [$this, 'onConnect']);$this->serv->on('Receive', [$this, 'onReceive']);$this->serv->on('Close', [$this, 'onClose']);$this->serv->start();}public function onStart($serv){$this->echoStr("Server Starting");$this->timer = $serv->tick(1000, function(){$this->echoStr("timer waiting");});// $this->timer = swoole_timer_tick(1000, function() {// });}public function onConnect($serv, $fd, $from_id){// swoole_timer_clear($this->timer);$serv->clearTimer($this->timer);$this->echoStr("Connecting! Clear Timer!");// $serv->send($fd, "Hello {$fd}!");}public function onReceive(swoole_server $serv, $fd, $from_id, $data){$this->echoStr("Get Message From Client {$fd}:{$data}");$serv->send($fd, $data);}public function onClose($serv, $fd, $from_id){$this->echoStr("Client {$fd} close connection");}public function echoStr($msg){echo '[' . date('Y-m-d H:i:s') . ']: ' . $msg . PHP_EOL;} } // 啟動服務器 Start the server $server = new Server();

本意圖實現server啟動后循環輸出“timer waiting”,client連接后清除定時器的效果,然而onStart事件是在Master進程的主線程中被調用,而onConnect事件是在work進程中被回調,這里不屬于同一進程,故client連接后會提示:

PHP Warning: SwooleServer::clearTimer(): no timer...

原文地址:https://segmentfault.com/a/1190000016558928

轉載于:https://www.cnblogs.com/lalalagq/p/9969009.html

總結

以上是生活随笔為你收集整理的swoole 清除定时器提示no timer的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。