This commit is contained in:
xl
2024-11-18 13:53:50 +08:00
parent 64514b069e
commit 7f93ab046b
+16 -6
View File
@@ -70,17 +70,14 @@ class HotReload extends AbstractProcess
public function process(Process|null $process): void
{
$this->pipe = inotify_init();
foreach (config('reload.listen') as $value) {
$this->readDirectory($value);
}
while (!$this->isStop()) {
$read = inotify_read($this->pipe);
foreach ($read as $item) {
$this->reWatch($item['wd']);
if (!empty($read)) {
$this->reload();
}
$this->reload();
}
}
@@ -95,10 +92,18 @@ class HotReload extends AbstractProcess
}
$this->reloading = true;
foreach ($this->watches as $key => $watch) {
inotify_rm_watch($this->pipe, $key);
}
\Kiri::getLogger()->info('reloading server, please waite.');
di(ServerInterface::class)->reload();
foreach (config('reload.listen') as $value) {
$this->readDirectory($value);
}
$this->reloading = false;
}
@@ -126,7 +131,12 @@ class HotReload extends AbstractProcess
if (isset($this->watches[$directory])) {
inotify_rm_watch($this->pipe, $directory);
inotify_add_watch($this->pipe, $this->watches[$directory], IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
$path = $this->watches[$directory];
unset($this->watches[$directory]);
$data = inotify_add_watch($this->pipe, $path, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
$this->watches[$data] = $path;
}
}