改名
This commit is contained in:
+18
-8
@@ -175,13 +175,7 @@ class Server extends HttpService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach ($port as $value) {
|
foreach ($port as $value) {
|
||||||
if (Snowflake::getPlatform()->isLinux()) {
|
if ($this->checkPort($value['port'])) {
|
||||||
exec('netstat -tunlp | grep ' . $value['port'], $output);
|
|
||||||
} else {
|
|
||||||
exec('lsof -i :' . $value['port'] . ' | grep -i "LISTEN"', $output);
|
|
||||||
}
|
|
||||||
if (!empty($output)) {
|
|
||||||
unset($output);
|
|
||||||
return true;
|
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
|
* @return void
|
||||||
*
|
*
|
||||||
@@ -312,7 +322,7 @@ class Server extends HttpService
|
|||||||
*/
|
*/
|
||||||
private function dispatchCreate($config, $settings): \Swoole\Server|Packet|Receive|Http|Websocket|null
|
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']);
|
return $this->error_stop($config['host'], $config['port']);
|
||||||
}
|
}
|
||||||
if (!($this->baseServer instanceof \Swoole\Server)) {
|
if (!($this->baseServer instanceof \Swoole\Server)) {
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ class Service extends Component
|
|||||||
private function addService($router, $server, $service)
|
private function addService($router, $server, $service)
|
||||||
{
|
{
|
||||||
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
|
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
|
||||||
|
|
||||||
|
if (Snowflake::port_already($service['port'])) {
|
||||||
|
throw new Exception(sprintf('Port %s::%d is already.', $service['host'], $service['port']));
|
||||||
|
}
|
||||||
|
$this->debug(sprintf('Port %s::%d is already.', $service['host'], $service['port']));
|
||||||
|
|
||||||
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
|
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
|
||||||
$rpcServer->set([
|
$rpcServer->set([
|
||||||
'open_tcp_keepalive' => true,
|
'open_tcp_keepalive' => true,
|
||||||
|
|||||||
@@ -83,6 +83,25 @@ class Snowflake
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $port
|
||||||
|
* @return bool|array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function port_already($port): bool
|
||||||
|
{
|
||||||
|
if (empty($port)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Snowflake::getPlatform()->isLinux()) {
|
||||||
|
exec('netstat -tunlp | grep ' . $port, $output);
|
||||||
|
} else {
|
||||||
|
exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output);
|
||||||
|
}
|
||||||
|
return !empty($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $className
|
* @param $className
|
||||||
* @param array $construct
|
* @param array $construct
|
||||||
|
|||||||
Reference in New Issue
Block a user