|
@@ -59,28 +59,21 @@ class WebSocketClient
|
|
|
}
|
|
|
|
|
|
$this->isRunning = true;
|
|
|
- $lastHeartbeat = time();
|
|
|
|
|
|
while ($this->isRunning) {
|
|
|
try {
|
|
|
- // 检查是否需要发送心跳
|
|
|
- if (time() - $lastHeartbeat >= $this->options['heartbeat_interval']) {
|
|
|
- $this->sendHeartbeat();
|
|
|
- $lastHeartbeat = time();
|
|
|
- }
|
|
|
-
|
|
|
+ $this->sendHeartbeat();
|
|
|
// 接收消息
|
|
|
$message = $this->socket->receive();
|
|
|
if ($message) {
|
|
|
$this->dispatchBinaryMessage($message);
|
|
|
}
|
|
|
-
|
|
|
- usleep(10000); // 10ms 避免CPU过高使用
|
|
|
+ usleep(5); // 5ms 避免CPU过高使用
|
|
|
} catch (\WebSocket\ConnectionException $e) {
|
|
|
- $this->handleDisconnect($e);
|
|
|
- $lastHeartbeat = time(); // 重置心跳时间
|
|
|
+ error_log("ConnectionException 错误: " . $e->getMessage());
|
|
|
+ // $this->handleDisconnect($e);
|
|
|
} catch (\Exception $e) {
|
|
|
- error_log("错误: " . $e->getMessage());
|
|
|
+ error_log("Exception 错误: " . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|