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