https://github.com/thecodeholic/php-file-watcher
Watch file or folder and execute code when something is changes inside
https://github.com/thecodeholic/php-file-watcher
Last synced: 7 months ago
JSON representation
Watch file or folder and execute code when something is changes inside
- Host: GitHub
- URL: https://github.com/thecodeholic/php-file-watcher
- Owner: thecodeholic
- Created: 2019-12-24T05:41:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-02T13:09:10.000Z (almost 6 years ago)
- Last Synced: 2025-03-21T22:41:23.413Z (8 months ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 22
- Watchers: 2
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# php-file-watcher
Watch file or folder and execute code when something is changed inside
### Demo
You can run the following command to see how the script works
```sh
php index.php FILE_OR_FOLDER_PATH
```
### Basic usage
```php
$watcher = new \tc\fswatcher\Watcher('FILE_OR_FOLDER_PATH_TO_WATCH', function ($event) {
// Do whatever you want when file or folder is changed.
if ($event->isAddition()){
// File was added and file path will be $event->file
} else if ($event->isModification()){
// File was modified and file path will be $event->file
}
});
$watcher->watch();
```
### Advanced Usage
```php
$watcher = new \tc\fswatcher\Watcher('FILE_OR_FOLDER_PATH_TO_WATCH', 'callback', [
'watchInterval' => 5,
'cacheChanges' => true
]);
```
### Options
| Option | Default value | Description |
|---------------|---------------|------------------------------------------------------------------|
| watchInterval | 1 | How often the file changes should be checked |
| cacheChanges | true | Gather file modifications in single check and trigger event once |