This commit is contained in:
2020-10-14 10:57:50 +08:00
parent 1aa1a175b0
commit fe0413ef68
+24 -12
View File
@@ -76,26 +76,38 @@ trait Action
{ {
echo 'waite.'; echo 'waite.';
while ($server->isRunner()) { while ($server->isRunner()) {
$this->masterIdCheck();
usleep(100);
}
echo PHP_EOL;
}
/**
* WorkerId Iterator
*/
private function masterIdCheck()
{
echo '.'; echo '.';
$pods = glob(storage(null, 'worker') . '/*'); $files = new \DirectoryIterator($this->getWorkerPath());
if (count($pods) < 1) { foreach ($files as $file) {
break; $content = file_get_contents($file->getRealPath());
}
foreach ($pods as $pid) {
if (!file_exists($pid)) {
continue;
}
$content = file_get_contents($pid);
exec("ps -ax | awk '{ print $1 }' | grep -e '^{$content}$'", $output); exec("ps -ax | awk '{ print $1 }' | grep -e '^{$content}$'", $output);
if (count($output) > 0) { if (count($output) > 0) {
$this->closeByPid($content); $this->closeByPid($content);
} else { } else {
file_exists($pid) && @unlink($pid); @unlink($file->getRealPath());
} }
} }
usleep(100);
} }
echo PHP_EOL;
/**
* @return string
*/
private function getWorkerPath()
{
return "glob://" . ltrim(APP_PATH, '/') . '/storage/worker/*.sock';
} }