https://github.com/takuya/php-fsnotifywait-wrapper
fsnotifywait of fanotify command wrapper
https://github.com/takuya/php-fsnotifywait-wrapper
Last synced: 4 months ago
JSON representation
fsnotifywait of fanotify command wrapper
- Host: GitHub
- URL: https://github.com/takuya/php-fsnotifywait-wrapper
- Owner: takuya
- License: agpl-3.0
- Created: 2025-04-04T15:43:04.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-09T03:23:23.000Z (about 1 year ago)
- Last Synced: 2025-08-12T15:40:44.112Z (10 months ago)
- Language: PHP
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## php fsnotify wrapper
Utilize `fsnotifywait` command.
```php
addObserver($observer = new FsEventObserver());
$observer->watch(function(FanEvent $ev ){
$this->queue->push($ev->getEventSource());
});
$fsnotify->listen();
```
Watch delete event
```php
$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.
```php
{#372
+"time": "2025-04-04 23:50:31"
+"type": "CREATE"
+"file": "/tmp/php-tmpdir-gUEKhP8s/sample.txt"
}
```
## installation
```shell
composer require takuya/php-fsnotifywait-wrapper
```
## command
Watch command included.
```php
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.
```shell
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.
```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
```
## see
- man fanotify
- man fsnotifywatch
- man fsnotifywait