System tools & monitoring programs are often required to monitor a directory or file(s) for changes, not just content changes, it may even be attribute changes like permissions, timestamps etc. Inotify is being used for quite some time in C programming to achieve the same.

Here we will be looking at enabling inotify support for PHP, and look at a few code snippets at how about using it. The on criteria for for using inotify is that it'll only work on a Linux system.

Enabling/Installing Inotify

Inotify is available as a PECL package, first get PECL from http://pecl.php.net/ if you do not already have it. After doing that just issue the following command as a root user:

// now we'll also have to check for the type of eventif($events['mask'] & IN_CREATE){print"New file downloaded ".$events['name']."\n";}elseif($events['mask'] & IN_MODIFY){print"File modified ".$events['name']."\n";}

}

// clean upinotify_rm_watch($fd, $watch_descriptor);

fclose($fd);?>

Similarly you can also watch files for changes, I hope this article was helpful. Enjoy.

marlonmark

17Dec2012 12:58

Re: Monitor Filesystem Changes in PHP

Thank you sir thats the cool and the descriptive way to make me understand.