This commit is contained in:
2021-03-02 12:08:21 +08:00
parent 56d4d5dcb7
commit 53b8262588
2 changed files with 9 additions and 12 deletions
+7 -6
View File
@@ -12,6 +12,7 @@ use Snowflake\Abstracts\Input;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\WebSocket\Server;
/**
@@ -55,9 +56,9 @@ trait Action
return;
}
$content = file_get_contents($pid_file);
exec("ps -ef $content | grep $content", $output);
Coroutine\System::exec("ps -ef $content | grep $content", $output);
if (!empty($output)) {
exec("kill -15 $content");
Coroutine\System::exec("kill -15 $content");
}
$this->close($server);
}
@@ -107,7 +108,7 @@ trait Action
}
foreach ($files as $file) {
$content = file_get_contents($file->getRealPath());
exec("ps -ax | awk '{ print $1 }' | grep -e '^{$content}$'", $output);
Coroutine\System::exec("ps -ax | awk '{ print $1 }' | grep -e '^{$content}$'", $output);
if (count($output) > 0) {
$this->closeByPid($content);
} else {
@@ -137,9 +138,9 @@ trait Action
return false;
}
if (Snowflake::isLinux()) {
exec('netstat -tunlp | grep ' . $port, $output);
Coroutine\System::exec('netstat -tunlp | grep ' . $port, $output);
} else {
exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output);
Coroutine\System::exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output);
}
if (empty($output)) {
return false;
@@ -153,7 +154,7 @@ trait Action
*/
private function closeByPid($pid)
{
exec("ps -ef | grep $pid | grep -v grep | grep -v kill
Coroutine\System::exec("ps -ef | grep $pid | grep -v grep | grep -v kill
if [ $? -eq 0 ];then
kill -9 `ps -ef | grep $pid | grep -v grep | grep -v kill | awk '{print $2}'`
else