From 8a9cfc0e6c4018f47e17376bf9db3c53f7b5e5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 18:29:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Server.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/HttpServer/Server.php b/HttpServer/Server.php index c899b71b..2be56c46 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -94,11 +94,6 @@ class Server extends Application public function start() { $configs = Config::get('servers', true); - foreach ($configs as $config) { - if ($this->isUse($config['port'])) { - return $this->error_stop($config['host'], $config['port']); - } - } Snowflake::clearWorkerId(); $baseServer = $this->initCore($configs); $baseServer->start(); @@ -113,6 +108,9 @@ class Server extends Application public function error_stop($host, $Port) { $this->error(sprintf('Port %s::%d is already.', $host, $Port)); + if ($this->baseServer) { + $this->baseServer->shutdown(); + } } @@ -260,6 +258,9 @@ class Server extends Application { if (!($this->baseServer instanceof \Swoole\Server)) { $class = $this->dispatch($config['type']); + if ($this->isUse($config['port'])) { + return $this->error_stop($config['host'], $config['port']); + } $this->baseServer = new $class($config['host'], $config['port'], SWOOLE_PROCESS, $config['mode']); $settings['daemonize'] = $this->daemon; if (!isset($settings['pid_file'])) { @@ -301,6 +302,9 @@ class Server extends Application */ private function onListenerBind($config, $newListener) { + if ($this->isUse($config['port'])) { + return $this->error_stop($config['host'], $config['port']); + } $this->debug(sprintf('Listener %s::%d', $config['host'], $config['port'])); if ($config['type'] == self::HTTP) { $this->onBind($newListener, 'request', [Snowflake::createObject(OnRequest::class), 'onHandler']);