From 4f7e464c86f411a1849f071244e5d8ef7a0a9341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 3 Sep 2020 01:28:55 +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 | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/system/Process/ServerInotify.php b/system/Process/ServerInotify.php index 6d8f2901..99bd9536 100644 --- a/system/Process/ServerInotify.php +++ b/system/Process/ServerInotify.php @@ -47,20 +47,49 @@ class ServerInotify extends Process Event::add($this->inotify, [$this, 'check']); Event::wait(); } else { - Timer::tick(10000, [$this, 'tick']); + Timer::tick(1000, [$this, 'tick']); } } + private $md5Map = []; + + /** * @throws Exception */ public function tick() { $this->debug('file modify listener.'); - $this->reload(); + + $this->loadByDir(APP_PATH . '/app'); } + + /** + * @param $path + * @return void + * @throws Exception + */ + private function loadByDir($path) + { + $path = rtrim($path, '/'); + foreach (glob($path . '/*') as $value) { + $md5 = md5($value); + + if (is_dir($value)) { + $this->loadByDir($value); + } + if (!isset($this->md5Map[$md5])) { + return $this->reload(); + } + if ($this->md5Map[$md5] != filectime($value)) { + return $this->reload(); + } + } + } + + /** * 开始监听 */