This commit is contained in:
2020-11-17 16:56:25 +08:00
parent 767f726512
commit 215122b2cb
+24 -6
View File
@@ -77,7 +77,7 @@ class ServerInotify extends Process
/** /**
* @param $path * @param $path
* @param bool $isReload * @param bool $isReload
* @return void * @return void|mixed
* @throws Exception * @throws Exception
*/ */
private function loadByDir($path, $isReload = false) private function loadByDir($path, $isReload = false)
@@ -89,26 +89,41 @@ class ServerInotify extends Process
foreach (glob($path . '/*') as $value) { foreach (glob($path . '/*') as $value) {
if (is_dir($value)) { if (is_dir($value)) {
$this->loadByDir($value, $isReload); $this->loadByDir($value, $isReload);
}
if (is_file($value)) {
if ($this->checkFile($value, $isReload)) {
continue; continue;
} }
$this->timerReload();
break;
}
}
}
/**
* @param $value
* @param $isReload
* @return bool
*/
private function checkFile($value, $isReload)
{
$md5 = md5($value); $md5 = md5($value);
$mTime = filectime($value); $mTime = filectime($value);
if (!isset($this->md5Map[$md5])) { if (!isset($this->md5Map[$md5])) {
if ($isReload) { if ($isReload) {
$this->isReloading = true; return true;
return Timer::after(2000, [$this, 'timerReload']);
} }
$this->md5Map[$md5] = $mTime; $this->md5Map[$md5] = $mTime;
} else { } else {
if ($this->md5Map[$md5] != $mTime) { if ($this->md5Map[$md5] != $mTime) {
if ($isReload) { if ($isReload) {
$this->isReloading = true; return true;
return Timer::after(2000, [$this, 'timerReload']);
} }
$this->md5Map[$md5] = $mTime; $this->md5Map[$md5] = $mTime;
} }
} }
} return false;
} }
@@ -176,6 +191,9 @@ class ServerInotify extends Process
*/ */
public function timerReload() public function timerReload()
{ {
if ($this->isReloading) {
return;
}
$this->isReloading = true; $this->isReloading = true;
$this->trigger_reload(); $this->trigger_reload();
$this->int = -1; $this->int = -1;