From db32f0657807b20ecbf50d4bf9ea71688513aaff Mon Sep 17 00:00:00 2001 From: james Date: Tue, 3 Jun 2025 14:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20src/start.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/start.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/start.php b/src/start.php index aeaeeaa..b2db2a0 100644 --- a/src/start.php +++ b/src/start.php @@ -1,27 +1,19 @@ onConnect = function ($connection) { - echo "New connection\n"; -}; +$ws_worker->onConnect = [$handler, 'onConnect']; +$ws_worker->onMessage = [$handler, 'onMessage']; +$ws_worker->onClose = [$handler, 'onClose']; -// Emitted when data received -$ws_worker->onMessage = function ($connection, $data) { - // Send hello $data - $connection->send('Hello ' . $data); -}; - -// Emitted when connection closed -$ws_worker->onClose = function ($connection) { - echo "Connection closed\n"; -}; - -// Run worker -Worker::runAll(); \ No newline at end of file +// 仅在非测试环境下运行 +if (!getenv('PHPUNIT_RUNNING')) { + Worker::runAll(); +} \ No newline at end of file