This commit is contained in:
as2252258@163.com
2021-07-26 03:45:46 +08:00
parent d56c2bba9e
commit c812f9c110
+20 -2
View File
@@ -95,8 +95,7 @@ class ServerManager extends Abstracts\Server
$context = ServerManager::getContext(); $context = ServerManager::getContext();
foreach ($this->sortService($configs['ports']) as $config) { foreach ($this->sortService($configs['ports']) as $config) {
if ($this->checkPort($config['port'])) { if ($this->checkPort($config['port'])) {
$this->server->shutdown(); $this->stopServer($config['port']);
trigger_error(sprintf('Port %s::%d is already.', $config['host'], $config['port']));
} }
$this->startListenerHandler($context, $config); $this->startListenerHandler($context, $config);
} }
@@ -293,6 +292,25 @@ class ServerManager extends Abstracts\Server
} }
public function stopServer(int $port)
{
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
if (empty($output)) {
return;
}
$explode = explode('/', $output);
exec('kill -15 ' . $explode[0], $execResuklt);
while (true) {
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
if (empty($output)) {
return;
}
}
}
/** /**
* @param string $type * @param string $type
* @param array $settings * @param array $settings