From 215122b2cb010c3da3ff9f51266e3789442b545e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 17 Nov 2020 16:56:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Process/ServerInotify.php | 52 +++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/System/Process/ServerInotify.php b/System/Process/ServerInotify.php index 008c6f6e..3fe1ea23 100644 --- a/System/Process/ServerInotify.php +++ b/System/Process/ServerInotify.php @@ -77,7 +77,7 @@ class ServerInotify extends Process /** * @param $path * @param bool $isReload - * @return void + * @return void|mixed * @throws Exception */ private function loadByDir($path, $isReload = false) @@ -89,29 +89,44 @@ class ServerInotify extends Process foreach (glob($path . '/*') as $value) { if (is_dir($value)) { $this->loadByDir($value, $isReload); - continue; } - $md5 = md5($value); - $mTime = filectime($value); - if (!isset($this->md5Map[$md5])) { - if ($isReload) { - $this->isReloading = true; - return Timer::after(2000, [$this, 'timerReload']); - } - $this->md5Map[$md5] = $mTime; - } else { - if ($this->md5Map[$md5] != $mTime) { - if ($isReload) { - $this->isReloading = true; - return Timer::after(2000, [$this, 'timerReload']); - } - $this->md5Map[$md5] = $mTime; + if (is_file($value)) { + if ($this->checkFile($value, $isReload)) { + continue; } + $this->timerReload(); + break; } } } + /** + * @param $value + * @param $isReload + * @return bool + */ + private function checkFile($value, $isReload) + { + $md5 = md5($value); + $mTime = filectime($value); + if (!isset($this->md5Map[$md5])) { + if ($isReload) { + return true; + } + $this->md5Map[$md5] = $mTime; + } else { + if ($this->md5Map[$md5] != $mTime) { + if ($isReload) { + return true; + } + $this->md5Map[$md5] = $mTime; + } + } + return false; + } + + /** * 开始监听 */ @@ -176,6 +191,9 @@ class ServerInotify extends Process */ public function timerReload() { + if ($this->isReloading) { + return; + } $this->isReloading = true; $this->trigger_reload(); $this->int = -1;