https://github.com/huang-yi/swoole-watcher
A Swoole file watcher base on fswatch.
https://github.com/huang-yi/swoole-watcher
fswatch swoole watcher
Last synced: 4 months ago
JSON representation
A Swoole file watcher base on fswatch.
- Host: GitHub
- URL: https://github.com/huang-yi/swoole-watcher
- Owner: huang-yi
- License: mit
- Created: 2017-11-20T03:57:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-14T02:28:09.000Z (over 5 years ago)
- Last Synced: 2025-06-14T05:05:51.019Z (4 months ago)
- Topics: fswatch, swoole, watcher
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swoole Watcher
This package provides a file watcher.
## Installation
The current version only supports [fswatch](https://github.com/emcrisostomo/fswatch), so you'll have to install fswatch first.
```sh
# MacOS
brew install fswatch# Linux (building from Source)
wget https://github.com/emcrisostomo/fswatch/releases/download/{VERSION}/fswatch-{VERSION}.tar.gz
tar -xzvf fswatch-{VERSION}.tar.gz
cd fswatch-{VERSION} && ./configure && make && sudo make install && sudo ldconfig
```> A user who wishes to build fswatch should get a release [tarball](https://github.com/emcrisostomo/fswatch/releases)
Then, make sure you have [swoole](https://www.swoole.co.uk/) extension installed in PHP.
```sh
pecl install swoole
```Finally, you may install the Swoole Watcher via Composer:
```sh
composer require huang-yi/swoole-watcher
```## Usage
Create your watcher script like this:
```php
setOptions([
'--recursive' => true,
'--filter-from' => '/path/to/filter-rules-file',
]);$watcher = new Watcher($command);
// Registers a callback for an event.
$watcher->on(Fswatch::CREATED, function ($path) {
// do something...
});// or registers a default callback for any event.
$watcher->onChange(function ($events) {
// do something...
});$watcher->start();
```
## License
Swoole Watcher is open-sourced software licensed under the [MIT license](LICENSE).