This commit is contained in:
2021-03-23 19:03:48 +08:00
parent 48302c5067
commit 4c1dd409b0
3 changed files with 43 additions and 8 deletions
+18 -8
View File
@@ -175,13 +175,7 @@ class Server extends HttpService
return false;
}
foreach ($port as $value) {
if (Snowflake::getPlatform()->isLinux()) {
exec('netstat -tunlp | grep ' . $value['port'], $output);
} else {
exec('lsof -i :' . $value['port'] . ' | grep -i "LISTEN"', $output);
}
if (!empty($output)) {
unset($output);
if ($this->checkPort($value['port'])) {
return true;
}
}
@@ -189,6 +183,22 @@ class Server extends HttpService
}
/**
* @param $port
* @return bool
* @throws Exception
*/
private function checkPort($port): bool
{
if (Snowflake::getPlatform()->isLinux()) {
exec('netstat -tunlp | grep ' . $port, $output);
} else {
exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output);
}
return !empty($output);
}
/**
* @return void
*
@@ -312,7 +322,7 @@ class Server extends HttpService
*/
private function dispatchCreate($config, $settings): \Swoole\Server|Packet|Receive|Http|Websocket|null
{
if ($this->isUse($config['port'])) {
if (Snowflake::port_already($config['port'])) {
return $this->error_stop($config['host'], $config['port']);
}
if (!($this->baseServer instanceof \Swoole\Server)) {