This commit is contained in:
xl
2024-11-18 12:19:26 +08:00
parent 26bd43510e
commit ab1a18a886
+12 -7
View File
@@ -22,6 +22,12 @@ class HotReload extends AbstractProcess
protected bool $enable_coroutine = false;
/**
* @var array
*/
protected array $watches = [];
/**
* @var bool
*/
@@ -64,16 +70,14 @@ class HotReload extends AbstractProcess
public function process(Process|null $process): void
{
$this->pipe = inotify_init();
foreach (config('reload.listen') as $key => $value) {
$this->readDirectory($value);
foreach (config('reload.listen') as $value) {
$this->readFile($value);
}
while (!$this->isStop()) {
$read = inotify_read($this->pipe);
var_dump($read);
foreach ($read as $item) {
$this->reWatch($item['name']);
$this->reWatch($this->watches[$item['wd']]);
}
$this->reload();
@@ -105,9 +109,10 @@ class HotReload extends AbstractProcess
*/
public function readFile(string $directory): void
{
var_dump($directory);
if (str_ends_with($directory, '.php') === true) {
inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
$wd = inotify_add_watch($this->pipe, $directory, IN_MODIFY | IN_MOVE | IN_CREATE | IN_DELETE);
$this->watches[$wd] = $directory;
}
}