Categories: Tips & Tricks

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:

[php]
<?
$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);
?>
[/php]

Pradeep

Share
Published by
Pradeep
Tags: inotifyphp

Recent Posts

Update Google AMP Cache with Perl

While implementing Google AMP (Accelerated Mobile Pages) for your website, it might occur to you…

6 years ago

Don’t buy Reliance Jio’s JioFi Device or JioPhone – Avoid at all cost

Thinking of buying the JioFi device by reliance or to be precise any device by…

7 years ago

Solution for Copy Paste or right click disabled in Websites Chrome

Do you hate those pesky javascripts. Majority of the banking, utility bill payment etc so…

9 years ago

Sync personal ebooks with notes, bookmarks reading position on your Kindle

So amazon has this amazing feature called whispersync : If you read the same Kindle…

10 years ago

Google Authenticator: Moving To A New Phone

Getting a new HTC One left me wondering how will I move Google Authenticator from…

11 years ago

Electronic Arts Free Games! Free ITunes Gift Vouchers

Get Bad Company 2, ME: Infiltrator, etc for free Free Games you can get today:…

11 years ago