PHP code example of takuya / php-fsnotifywait-wrapper

1. Go to this page and download the library: Download takuya/php-fsnotifywait-wrapper 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/ */

    

takuya / php-fsnotifywait-wrapper example snippets



$fsnotify = new FsNotifyWrap('/etc');
$fsnotify->addObserver($observer = new FsEventObserver());
$observer->watch(function(FanEvent $ev ){
  $this->queue->push($ev->getEventSource());
});
$fsnotify->listen();

$fsnotify = new FsNotifyWrap('/etc');
$fsnotify->addObserver($observer = new FsEventObserver());
$observer->addEventListener(
   FsNotifyDelete:class,
  fn($ev)=>dump($ev->getEventSource());
);
$fsnotify->listen();

{#372
  +"time": "2025-04-04 23:50:31"
  +"type": "CREATE"
  +"file": "/tmp/php-tmpdir-gUEKhP8s/sample.txt"
}

sudo vendor/bin/fswatch -S --dir /home --exec /usr/bin/echo 
shell
composer 
shell
{"time":"2025-04-02 03:55:29","type":"CREATE"}:/opt/work/sample/aTooc8Eeph.txt
{"time":"2025-04-02 03:55:29","type":"MODIFY"}:/opt/work/sample/aTooc8Eeph.txt
{"time":"2025-04-02 03:55:29","type":"CREATE"}:/opt/work/sample/oFam1Aivoh.txt
{"time":"2025-04-02 03:55:29","type":"MODIFY"}:/opt/work/sample/oFam1Aivoh.txt
{"time":"2025-04-02 03:55:29","type":"CREATE"}:/opt/work/sample/jumaiPuSh2.txt
{"time":"2025-04-02 03:57:42","type":"CREATE,ISDIR"}:/opt/work/sample/sub