This commit is contained in:
as2252258@163.com
2021-07-26 01:30:50 +08:00
parent 82350f3c81
commit 6d49bffcfe
+20
View File
@@ -94,12 +94,32 @@ class ServerManager extends Abstracts\Server
{
$context = ServerManager::getContext();
foreach ($this->sortService($configs['ports']) as $config) {
if ($this->checkPort($config['port'])) {
$this->server->shutdown();
trigger_error(sprintf('Port %s::%d is already.', $config['host'], $config['port']));
}
$this->startListenerHandler($context, $config);
}
$this->addServerEventCallback($this->getSystemEvents($configs));
}
/**
* @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);
}
/**
* @param string|CustomProcess $customProcess
* @param null $redirect_stdin_and_stdout