inotify = $fd = inotify_init(); $this->addWatcher(DataProvider::getSourceRootDir() . "/src", $fd); Event::add($fd, function () use ($fd) { $r = inotify_read($fd); Console::verbose("File updated: " . $r[0]["name"]); ZMUtil::reload(); }); } else { Console::warning(zm_internal_errcode("E00024") . "You have not loaded \"inotify\" extension, please install first."); } } if (Framework::$argv["interact"]) { Console::info("Interact mode"); ZMBuf::$terminal = $r = STDIN; Event::add($r, function () use ($r) { $fget = fgets($r); if ($fget === false) { Event::del($r); return; } $var = trim($fget); if ($var == "stop") Event::del($r); try { Terminal::executeCommand($var); } catch (Exception $e) { Console::error(zm_internal_errcode("E00025") . "Uncaught exception " . get_class($e) . ": " . $e->getMessage() . " at " . $e->getFile() . "(" . $e->getLine() . ")"); } catch (Error $e) { Console::error(zm_internal_errcode("E00025") . "Uncaught error " . get_class($e) . ": " . $e->getMessage() . " at " . $e->getFile() . "(" . $e->getLine() . ")"); } }); } }); self::$process->set(['enable_coroutine' => true]); self::$process->start(); Console::verbose("进程 Manager 已启动"); } private function addWatcher($maindir, $fd) { $dir = scandir($maindir); if ($dir[0] == ".") { unset($dir[0], $dir[1]); } foreach ($dir as $subdir) { if (is_dir($maindir . "/" . $subdir)) { Console::debug("添加监听目录:" . $maindir . "/" . $subdir); inotify_add_watch($fd, $maindir . "/" . $subdir, IN_ATTRIB | IN_ISDIR); $this->addWatcher($maindir . "/" . $subdir, $fd); } } } }