pipe); var_dump('ddddddddddddddd'); $this->stop(); var_dump('ddddddddddddddd1111111111111111111111'); } /** * @param ?Process $process */ public function process(Process|null $process): void { $this->addListen(); Event::cycle(function (): void { if ($this->isStop()) { $read = inotify_read($this->pipe); if (!empty($read)) { $this->reload(); } } else { Event::exit(); } Event::dispatch(); }); Event::wait(); } /** * @return void */ public function reload(): void { if ($this->reloading) { return; } $this->reloading = true; $this->logger->error('reloading server, please waite.'); $this->clear(); di(ServerInterface::class)->reload(); $this->addListen(); $this->reloading = false; } /** * @return void */ protected function addListen(): void { $this->pipe = inotify_init(); foreach (config('reload.listen') as $value) { $this->readDirectory($value); } } /** * @return void */ protected function clear(): void { foreach ($this->watches as $key => $watch) { inotify_rm_watch($this->pipe, $key); } } /** * @param string $directory * @return void */ public function readFile(string $directory): void { if (str_ends_with($directory, '.php') === true) { $wd = inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE); $this->watches[$wd] = $directory; } } /** * @param int $directory * @return void */ public function reWatch(int $directory): void { if (isset($this->watches[$directory])) { inotify_rm_watch($this->pipe, $directory); $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; } } /** * @param string $directory * @return void */ public function readDirectory(string $directory): void { foreach (glob($directory . '/*') as $data) { if (is_dir($data)) { $this->readDirectory($data); } else { $this->readFile($data); } } } }