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]

Do not forget to share if you like:
Pradeep

Recent Posts

Self-hosting free password manager : Vaultwarden

Bitwarden is an open-source password manager that helps individuals and organizations securely store, manage, and…

9 months ago

Get Started with IPTV: Free and Paid Options for All Devices

In today's digital age, traditional cable TV is steadily being replaced by more flexible and…

11 months ago

Installing Log2RAM utility on your Raspberry Pi

log2ram is a utility specifically designed for Linux-based systems, particularly single-board computers like the Raspberry…

11 months ago

ChatGPT Voice Shortcut on iOS, Android

How to Add a ChatGPT Voice Shortcut on iOS and Android With voice commands and…

11 months ago

Proxy Through SSH Tunnel

For occasional VPN or proxy, you do not always need to pay for a reliable…

1 year ago

Unlocking the Power of Time Machine: The Easiest Way to Back Up Your Mac

When it comes to protecting your Mac, Time Machine offers an effortless and powerful way to keep…

1 year ago