dreadnip / php-inotify
Wraps php inotify module into object and dispatch them using event dispatcher.
v3.0.1
2022-04-04 12:26 UTC
Requires
- php: ^8.1
- ext-inotify: *
- ext-json: *
- doctrine/collections: ^1.6
- symfony/event-dispatcher: ^4.0|^5.0|^6.0
Requires (Dev)
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-11-09 02:17:44 UTC
README
This is a PHP8.1 fork of the excellent package by krowinski.
Installation
composer require dreadnip/php-inotify
Installing inotify extension for php
To listen on event we need php extension called inotify. In most cases you just need to install using pecl:
pecl install inotify
(example in dockerfile)
Example
You can find example in example.php and events that you can listen to InotifyEventCodeEnum.php Event implement JsonSerializable and __toString.
Array ( [id] => 1 [eventCode] => 256 [eventDescription] => ON_CREATE - File or directory created in watched directory [uniqueId] => 0 [fileName] => 2 [pathName] => /tmp [customName] => test [pathWithFile] => /tmp/2 [timestamp] => 1565610455 ) Array ( [id] => 1 [eventCode] => 32 [eventDescription] => ON_OPEN - File was opened [uniqueId] => 0 [fileName] => 2 [pathName] => /tmp [customName] => test [pathWithFile] => /tmp/2 [timestamp] => 1565610455 ) Array ( [id] => 1 [eventCode] => 4 [eventDescription] => ON_ATTRIB - Metadata changed (e.g. permissions, mtime, etc.) [uniqueId] => 0 [fileName] => 2 [pathName] => /tmp [customName] => test [pathWithFile] => /tmp/2 [timestamp] => 1565610455 ) Array ( [id] => 1 [eventCode] => 8 [eventDescription] => ON_CLOSE_WRITE - File opened for writing was closed [uniqueId] => 0 [fileName] => 2 [pathName] => /tmp [customName] => test [pathWithFile] => /tmp/2 [timestamp] => 1565610455 ) Array ( [id] => 1 [eventCode] => 512 [eventDescription] => ON_DELETE - File or directory deleted in watched directory [uniqueId] => 0 [fileName] => 2 [pathName] => /tmp [customName] => test [pathWithFile] => /tmp/2 [timestamp] => 1565610456 )
Where:
[id] => watch descriptor
[eventCode] => bit mask of events
[eventDescription] => human readable event description (can be UNKNOWN if not found in InotifyEventCodeEnum)
[uniqueId] => is a unique id to connect related events (e.g. IN_MOVE_FROM and IN_MOVE_TO)
[fileName] => name of a file (e.g. if a file was modified in a watched directory)
[pathName] => watched resource you give in configuration
[customName] => custom resource name for external parsing like "form-upload-dir" etc
[pathWithFile] => helper that contact pathName and fileName
[timestamp] => ...