takuya / php-fsnotifywait-wrapper
fsnotifywait of fanotify command wrapper
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/takuya/php-fsnotifywait-wrapper
Requires
- takuya/php-process-exec: ^0.1.1
Requires (Dev)
- ext-posix: *
- phpunit/phpunit: ^9.6
- takuya/php-sysv-ipc-info: ^0.1.0
- takuya/php-sysv-ipc-message-queue: ^0.1.2
This package is auto-updated.
Last update: 2025-10-09 04:32:16 UTC
README
Utilize fsnotifywait command.
<?php $fsnotify = new FsNotifyWrap('/etc'); $fsnotify->addObserver($observer = new FsEventObserver()); $observer->watch(function(FanEvent $ev ){ $this->queue->push($ev->getEventSource()); }); $fsnotify->listen();
Watch delete event
$fsnotify = new FsNotifyWrap('/etc'); $fsnotify->addObserver($observer = new FsEventObserver()); $observer->addEventListener( FsNotifyDelete:class, fn($ev)=>dump($ev->getEventSource()); ); $fsnotify->listen();
EventSource is a simple object like This.
{#372
+"time": "2025-04-04 23:50:31"
+"type": "CREATE"
+"file": "/tmp/php-tmpdir-gUEKhP8s/sample.txt"
}
installation
composer require takuya/php-fsnotifywait-wrapper
command
Watch command included.
sudo vendor/bin/fswatch -S --dir /home --exec /usr/bin/echo
If something changed, exec echo.sh
about fsnotifywait
fsnotifywait can be added as Linux Command. run apt install inotofy-tools.
This command can watch file changed by fanotify API. fanotify is added Linux Kernel 5.10.
Compare inotifywatch, fsnotifywait uses FAN( fanotify API not inotify).
fanotify API can watch arbitrarily chosen dir, and recursively too many file in it which inotify cannot watch.
fsnotifywait -q --format '#%w%f %e ::::' -m -r -S -e create,delete,move,modify /mnt/sample
fsnotifywait -q --timefmt '%F %T' --format '{"time":"%T","type":"%e"}:%w%f%0' -m -r -F -e create,delete,move,modify,moved_from,moved_to /opt/work/sample/
This command will output this.
{"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
see
- man fanotify
- man fsnotifywatch
- man fsnotifywait