This commit is contained in:
2026-07-15 10:41:18 +08:00
parent ebcb7237ef
commit 47ab439325
+42 -42
View File
@@ -212,47 +212,47 @@ if (!function_exists('call')) {
} }
if (!function_exists('checkPortIsAlready')) { if (!function_exists('checkPortIsAlready')) {
/** /**
* @param $port * @param $port
* @return bool|string * @return bool|string
*/ */
function checkPortIsAlready($port): bool|string function checkPortIsAlready($port): bool|string
{ {
$port = (int)$port; $port = (int)$port;
if ($port <= 0) { if ($port <= 0) {
return FALSE; 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];
} }
exec('netstat -lnp 2>/dev/null | grep :' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output); exec('netstat -lnp 2>/dev/null | grep :' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
if (empty($output)) { if (empty($output)) {
exec('ss -ltnp 2>/dev/null | grep :' . $port . ' | sed -n \"s/.*pid=\\([0-9]*\\).*/\\1/p\"', $output); exec('ss -ltnp 2>/dev/null | grep :' . $port . ' | sed -n \"s/.*pid=\\([0-9]*\\).*/\\1/p\"', $output);
} }
if (empty($output)) { if (empty($output)) {
return FALSE; return FALSE;
} }
$pid = trim((string)$output[0]); $pid = trim((string)$output[0]);
if (str_contains($pid, '/')) { if (str_contains($pid, '/')) {
$pid = explode('/', $pid)[0]; $pid = explode('/', $pid)[0];
} }
return $pid !== '' ? $pid : FALSE; return $pid !== '' ? $pid : FALSE;
} }
} }
if (!function_exists('set_env')) { if (!function_exists('set_env')) {
@@ -704,7 +704,7 @@ if (!function_exists('get_file_extension')) {
} else if (function_exists('finfo_open')) { } else if (function_exists('finfo_open')) {
$fInfo = finfo_open(FILEINFO_MIME); $fInfo = finfo_open(FILEINFO_MIME);
$mimeType = finfo_file($fInfo, $filename); $mimeType = finfo_file($fInfo, $filename);
finfo_close($fInfo); // finfo_close($fInfo);
$mimeType = current(explode('; ', $mimeType)); $mimeType = current(explode('; ', $mimeType));
if (!($search = array_search($mimeType, $mime_types))) { if (!($search = array_search($mimeType, $mime_types))) {
return $mimeType; return $mimeType;