Skip to content

Instantly share code, notes, and snippets.

@pedrosancao
Created July 25, 2020 18:11
Show Gist options
  • Save pedrosancao/6f6d8039e09fc1873bed42e1d1a8b735 to your computer and use it in GitHub Desktop.
Save pedrosancao/6f6d8039e09fc1873bed42e1d1a8b735 to your computer and use it in GitHub Desktop.
PHP inotify_add_watch recursive
<?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