Monitor Files & Directory For Modifications With PHP

One can monitor for changes to files & directories, including events like open, close, new file, delete, rename & all other file/directory operations.

The following code snippet should be self-explanatory:

<?
$data_file = '/var/data/my_data_file.txt';

$inotify_fd = inotify_init();

$watch_descriptor = inotify_add_watch($inotify_fd, $data_file, IN_OPEN);

while (1)
{
$events = inotify_read($inotify_fd);
$filepath = $events['name'];

print "File opened";
}

inotify_rm_watch($inotify_fd, $watch_descriptor);

fclose($inotify_fd);
?>

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

search engine optimization