eee
This commit is contained in:
+17
-9
@@ -218,33 +218,41 @@ if (!function_exists('checkPortIsAlready')) {
|
|||||||
/**
|
/**
|
||||||
* @param $port
|
* @param $port
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
* @throws
|
|
||||||
*/
|
*/
|
||||||
function checkPortIsAlready($port): bool|string
|
function checkPortIsAlready($port): bool|string
|
||||||
{
|
{
|
||||||
|
$port = (int)$port;
|
||||||
|
if ($port <= 0) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Kiri::getPlatform()->isLinux()) {
|
if (!Kiri::getPlatform()->isLinux()) {
|
||||||
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
||||||
if (empty($output))
|
if (empty($output)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
$output = explode(PHP_EOL, $output[0]);
|
$output = explode(PHP_EOL, $output[0]);
|
||||||
return $output[0];
|
return $output[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$serverPid = file_get_contents(storage('.swoole.pid'));
|
exec('netstat -lnp 2>/dev/null | grep :' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
||||||
if (!empty($serverPid) && shell_exec('ps -ef | grep ' . $serverPid . ' | grep -v grep')) {
|
if (empty($output)) {
|
||||||
Process::kill($serverPid, 0) && Process::kill($serverPid, SIGTERM);
|
exec('ss -ltnp 2>/dev/null | grep :' . $port . ' | sed -n \"s/.*pid=\\([0-9]*\\).*/\\1/p\"', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
|
||||||
if (empty($output)) {
|
if (empty($output)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return explode('/', $output[0])[0];
|
|
||||||
|
$pid = trim((string)$output[0]);
|
||||||
|
if (str_contains($pid, '/')) {
|
||||||
|
$pid = explode('/', $pid)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pid !== '' ? $pid : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('set_env')) {
|
if (!function_exists('set_env')) {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user