Monthly Archives: February 2013

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);

search engine optimization