This commit is contained in:
2020-09-14 10:38:41 +08:00
parent 250ba50502
commit be3db38aae
+7 -5
View File
@@ -41,19 +41,20 @@ class ServerInotify extends Process
public function onHandler(\Swoole\Process $process) public function onHandler(\Swoole\Process $process)
{ {
set_error_handler([$this, 'onErrorHandler']); set_error_handler([$this, 'onErrorHandler']);
$this->dirs = Config::get('inotify', false, [APP_PATH]);
if (extension_loaded('inotify')) { if (extension_loaded('inotify')) {
$this->inotify = inotify_init(); $this->inotify = inotify_init();
$this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE; $this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE;
$process->name('event: file change.'); $process->name('event: file change.');
$this->dirs = Config::get('inotify', false, [APP_PATH]);
foreach ($this->dirs as $dir) { foreach ($this->dirs as $dir) {
$this->watch($dir); $this->watch($dir);
} }
Event::add($this->inotify, [$this, 'check']); Event::add($this->inotify, [$this, 'check']);
Event::wait(); Event::wait();
} else { } else {
$this->loadByDir(APP_PATH . 'app'); foreach ($this->dirs as $dir) {
$this->loadByDir(APP_PATH . 'routes'); $this->loadByDir($dir);
}
Timer::tick(2000, [$this, 'tick']); Timer::tick(2000, [$this, 'tick']);
} }
} }
@@ -67,8 +68,9 @@ class ServerInotify extends Process
*/ */
public function tick() public function tick()
{ {
$this->loadByDir(APP_PATH . 'app', true); foreach ($this->dirs as $dir) {
$this->loadByDir(APP_PATH . 'routes', true); $this->loadByDir($dir, true);
}
} }