改名
This commit is contained in:
+47
-17
@@ -6,7 +6,6 @@ namespace HttpServer;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\Component;
|
||||||
use Snowflake\Exception\ConfigException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +50,7 @@ class Shutdown extends Component
|
|||||||
|
|
||||||
$master_pid = Server()->setting['pid_file'] ?? PID_PATH;
|
$master_pid = Server()->setting['pid_file'] ?? PID_PATH;
|
||||||
if (file_exists($master_pid)) {
|
if (file_exists($master_pid)) {
|
||||||
$this->close($master_pid);
|
$this->close(file_get_contents($master_pid));
|
||||||
}
|
}
|
||||||
$this->closeOther();
|
$this->closeOther();
|
||||||
}
|
}
|
||||||
@@ -109,33 +108,64 @@ class Shutdown extends Component
|
|||||||
*/
|
*/
|
||||||
public function directoryCheck(string $path): bool
|
public function directoryCheck(string $path): bool
|
||||||
{
|
{
|
||||||
$dir = new \DirectoryIterator($path);
|
$values = $this->getProcessPidS($path);
|
||||||
if ($dir->getSize() < 1) {
|
if (empty($values)) return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
foreach ($dir as $value) {
|
|
||||||
if ($value->isDot()) continue;
|
|
||||||
|
|
||||||
if (!$value->valid()) continue;
|
$diff = array_diff($values, $this->getPidS());
|
||||||
|
foreach ($diff as $value) {
|
||||||
$this->close($value->getRealPath());
|
$this->pidIsExists($value);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $value
|
* @param $path
|
||||||
|
* @return array|bool
|
||||||
*/
|
*/
|
||||||
public function close(string $value)
|
private function getProcessPidS($path): bool|array
|
||||||
{
|
{
|
||||||
$content = file_get_contents($value);
|
$values = [];
|
||||||
|
$dir = new \DirectoryIterator($path);
|
||||||
|
if ($dir->getSize() < 1) {
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
foreach ($dir as $value) {
|
||||||
|
if ($value->isDot()) continue;
|
||||||
|
|
||||||
while ($this->pidIsExists($content)) {
|
if (!$value->valid()) continue;
|
||||||
exec('kill -15 ' . $content);
|
|
||||||
usleep(100);
|
$_value = file_get_contents($value->getRealPath());
|
||||||
|
if (empty($_value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$values[] = intval($_value);
|
||||||
|
}
|
||||||
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getPidS(): array
|
||||||
|
{
|
||||||
|
exec('ps -eo pid', $output);
|
||||||
|
return array_filter($output, function ($value) {
|
||||||
|
return intval($value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function close(mixed $value)
|
||||||
|
{
|
||||||
|
while ($this->pidIsExists($value)) {
|
||||||
|
exec('kill -15 ' . $value);
|
||||||
|
usleep(100);
|
||||||
|
}
|
||||||
clearstatcache($value);
|
clearstatcache($value);
|
||||||
if (file_exists($value)) {
|
if (file_exists($value)) {
|
||||||
@unlink($value);
|
@unlink($value);
|
||||||
|
|||||||
Reference in New Issue
Block a user