-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Filesystem] Add watch method to watch filesystem for changes #31462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3c9f3e7
78c9969
86ae251
23f09e6
5b31568
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,16 @@ public function watch($path, callable $callback, float $timeout = null) | |
stream_set_blocking($inotifyInit, false); | ||
|
||
$isDir = is_dir($path); | ||
$watchers = []; | ||
|
||
if ($isDir) { | ||
$watchId = inotify_add_watch($inotifyInit, $path, IN_CREATE | IN_DELETE | IN_MODIFY); | ||
$watchers[] = inotify_add_watch($inotifyInit, $path, IN_CREATE | IN_DELETE | IN_MODIFY); | ||
|
||
foreach ($this->scanPath("$path/*") as $path) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how does this work in https://github.com/flint/Lurker, because upon quick inspection, not only I don't see this mechanism there, but also no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Checking recursively can maybe be turned off by default and enabled by either a flag or a new method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks, GH didn't find it for me.
I don't mean to have ability to turn recursivity off, I am just trying to figure if there isn't smarter way to go around handling recursivity. First thing we need to clear up is: Is it absolute requirement for inotify PHP extension to create watcher for every subdirectory, instead of just parent directory? |
||
$watchers[] = inotify_add_watch($inotifyInit, $path, IN_CREATE | IN_DELETE | IN_MODIFY); | ||
} | ||
} else { | ||
$watchId = inotify_add_watch($inotifyInit, $path, IN_MODIFY); | ||
$watchers[] = inotify_add_watch($inotifyInit, $path, IN_MODIFY); | ||
} | ||
|
||
try { | ||
|
@@ -77,8 +82,19 @@ public function watch($path, callable $callback, float $timeout = null) | |
} | ||
pierredup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} finally { | ||
inotify_rm_watch($inotifyInit, $watchId); | ||
foreach ($watchers as $watchId) { | ||
inotify_rm_watch($inotifyInit, $watchId); | ||
} | ||
|
||
fclose($inotifyInit); | ||
} | ||
} | ||
|
||
private function scanPath($path) | ||
pierredup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
foreach (glob($path, GLOB_ONLYDIR) as $directory) { | ||
yield $directory; | ||
yield from $this->scanPath("$directory/*"); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.