Created
July 25, 2020 18:11
-
-
Save pedrosancao/6f6d8039e09fc1873bed42e1d1a8b735 to your computer and use it in GitHub Desktop.
PHP inotify_add_watch recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param resource $inotify_instance | |
* @param string $pathname | |
* @param int $mask | |
* @return int[] watcher descriptors | |
*/ | |
function inotify_add_watch_recursive ($inotify, $path, $mask) | |
{ | |
$ids = [inotify_add_watch($inotify, $path, $mask)]; | |
if (is_dir($path)) { | |
foreach (glob($path . '/*', GLOB_ONLYDIR) as $subdir) { | |
$ids[] = inotify_add_watch($inotify, $subdir, $mask); | |
} | |
} | |
return $ids; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment