xy 3 周之前
父節點
當前提交
94abe09247
共有 1 個文件被更改,包括 5 次插入12 次删除
  1. 5 12
      src/WebSocketClient.php

+ 5 - 12
src/WebSocketClient.php

@@ -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());
             }
         }
     }