正在显示
1 个修改的文件
包含
13 行增加
和
4 行删除
| @@ -159,8 +159,14 @@ class Websocket | @@ -159,8 +159,14 @@ class Websocket | ||
| 159 | $this->pingState = false; | 159 | $this->pingState = false; |
| 160 | $this->timerCheck = swoole_timer_after(5000, function () { | 160 | $this->timerCheck = swoole_timer_after(5000, function () { |
| 161 | if (!$this->pingState) { | 161 | if (!$this->pingState) { |
| 162 | - output($this->desc, 'ping pong 超时,重新连接'); | ||
| 163 | - $this->connect($this->onOpen, $this->onMessage, $this->onClose, $this->onPing, $this->onPong); | 162 | + //未收到pong且10内未获取数据。假定已断开连接(存在未收到pong,但在传数据的情况。) |
| 163 | + if($this->lastRecvTime<time()-10){ | ||
| 164 | + output($this->desc, 'ping pong 超时且未收到数据,重新连接'); | ||
| 165 | + $this->connect($this->onOpen, $this->onMessage, $this->onClose, $this->onPing, $this->onPong); | ||
| 166 | + }else{ | ||
| 167 | + output($this->desc, 'ping pong 超时,再次ping'); | ||
| 168 | + $this->sendPing(); | ||
| 169 | + } | ||
| 164 | } | 170 | } |
| 165 | }); | 171 | }); |
| 166 | } | 172 | } |
| @@ -174,7 +180,10 @@ class Websocket | @@ -174,7 +180,10 @@ class Websocket | ||
| 174 | } | 180 | } |
| 175 | swoole_timer_clear($this->timerCheck); | 181 | swoole_timer_clear($this->timerCheck); |
| 176 | $this->timerPing = swoole_timer_after($this->pingDelay, function () { | 182 | $this->timerPing = swoole_timer_after($this->pingDelay, function () { |
| 177 | - $this->sendPing(); | 183 | + //防止重复ping |
| 184 | + if($this->pingState){ | ||
| 185 | + $this->sendPing(); | ||
| 186 | + } | ||
| 178 | }); | 187 | }); |
| 179 | } | 188 | } |
| 180 | -} | 189 | +} |
-
请 注册 或 登录 后发表评论