public function watch()
{
if ($this->inotify) {
$events = inotify_read($this->inotify);
if (!$events) {
return;
}
foreach ($events as $ev) {
$path = $this->descriptors[$ev['wd']];
if (!isset($this->files[$path])) {
continue;
}
$this->onFileChanged($path);
}
} else {
static $hash = [];
foreach ($this->files as $path => $v) {
if (!file_exists($path)) {
// file can be deleted
unset($this->files[$path]);
continue;
}
$mt = filemtime($path);
if (isset($hash[$path]) && $mt > $hash[$path]) {
$this->onFileChanged($path);
}
$hash[$path] = $mt;
}
}
}