modify
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user