PHP code example of brunonatali / inotify

1. Go to this page and download the library: Download brunonatali/inotify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brunonatali / inotify example snippets


use BrunoNatali\Inotify\Factory;
use React\EventLoop\Factory as LoopFactory;

$loop = LoopFactory::create();
try {
    $notify = new Factory($loop);
} catch ($e \Exception) {
    /**
     * Exception codes:
     * EXCEPTION_EXTENSION_LOAD -> Extension is not loaded
     * EXCEPTION_EXTENSION_INIT -> inotify initialization error
    */
}

$filePathName = __FILE__;

$notify->add($filePathName, IN_ATTRIB);
$notify->on(IN_ATTRIB, function () {
	echo "File touched";
});

$notify->add('/some/path/file.name', IN_ATTRIB | IN_MODIFY | IN_ACCESS);

$notify->remove('/some/path/file.name');

$notify->on(FLAG_NAME, function () {
	// Do some stuff
});

$notify->add('/some/path/file.name', IN_ATTRIB | IN_MODIFY | IN_ACCESS);
$notify->on(IN_ACCESS, function () {
	echo "My file was accessed"
});

[
    "somepathfile.name" => (int) unique inotify instance wide watch descriptor,
    "otherpathfile.ext" => (int) another unique inotify instance
]