diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 88b86c46..7d1a0994 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -391,7 +391,7 @@ class Server extends HttpService if (!isset($settings['pid_file'])) { $settings['pid_file'] = PID_PATH; } - $this->debug(sprintf('Check listen %s::%d -> ok', $config['host'], $config['port'])); + $this->debug(Snowflake::listen($config)); $this->onLoadWebsocketHandler(); if ($this->baseServer instanceof Http) { diff --git a/Rpc/Service.php b/Rpc/Service.php index af902a80..70b8e419 100644 --- a/Rpc/Service.php +++ b/Rpc/Service.php @@ -59,9 +59,9 @@ class Service extends Component $mode = $service['mode'] ?? SWOOLE_SOCK_TCP6; if (Snowflake::port_already($service['port'])) { - throw new Exception(sprintf('Port %s::%d is already.', $service['host'], $service['port'])); + throw new Exception($this->already($service)); } - $this->debug(sprintf('Port %s::%d is already.', $service['host'], $service['port'])); + $this->debug(Snowflake::listen($service)); $rpcServer = $server->addlistener($service['host'], $service['port'], $mode); $rpcServer->set([ @@ -72,7 +72,28 @@ class Service extends Component 'open_http_protocol' => false, 'open_websocket_protocol' => false, ]); - $router->addPortListen($service['port'], function () use ($service, $mode) { + $this->listenPort($service, $mode); + } + + + /** + * @param $service + * @return string + */ + private function already($service): string + { + return sprintf('Port %s::%d is already.', $service['host'], $service['port']); + } + + + /** + * @param $service + * @param $mode + * @throws Exception + */ + private function listenPort($service, $mode) + { + router()->addPortListen($service['port'], function () use ($service, $mode) { try { /** @var Request $request */ $request = Context::getContext('request'); diff --git a/System/Snowflake.php b/System/Snowflake.php index 5ed8529d..f1894474 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -102,6 +102,16 @@ class Snowflake } + /** + * @param $service + * @return string + */ + #[Pure] public static function listen($service): string + { + return sprintf('Check listen %s::%d -> ok', $service['host'], $service['port']); + } + + /** * @param $className * @param array $construct