Download the PHP package vox/file-watcher without Composer
On this page you can find all versions of the php package vox/file-watcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package file-watcher
PHP Inotify File Watcher
Installing
this library requires PHP 7.1+ and pecl inotify extension inotify
Usage
Usage is simple, first configure the context:
Then obtain the watcher instance:
Now, all you need is the callback actions for each possible event, like this:
there are other events to be listened:
- onMoved
- onOpened
- onModified
- onClosed
- onDeleted
Finaly call the dispatch event method to listen to filesystem changes:
Note that, this operation will block untill an event occurs, and returns imediately as soon an filesystem event on the watched folder happens. This block can be avoided setting the context blocking property to false, that way, if no event ocurred between the watcher instancing and the call of this method an empty array will be returned
The readEvents method
You may notice that the FolderWatcher class has a readEvents method, this method can be called in case you may need to get the events without dispatching the events. this method returns an array of Vox\FileWatcher\FileWatcherEvent, this class has various methods to help identify what is this event about:
- isDir
- isWatchedDir - returns true if this event refers to a dir wihch is currently beig watched
- isMovedFile
- isMovedFrom
- isMovedTo
- isCreated
- isModified
- isDeleted
- isOpened
- isClosed
- getOriginPath - if its a moved file, get the former path as SplFileInfo instance
- getPath - the file path as SplFileInfo instance
- getCookie - if the event has a cookie, than its a moved file, the cookie is what binds the moved from and moved to events
Note: not all the movedTo files has a origin path, only those that are moved between watched dirs, when a file comes from a directory wihch is not being watched it will have no moved from event, therefore no originPath
All versions of file-watcher with dependencies
ext-inotify Version *