huang-yi / swoole-watcher
Swoole 文件监视器。
v1.0.1
2020-04-14 02:26 UTC
Requires
- ext-swoole: ^4.0
- symfony/process: ^3.3|^4.0|^5.0
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-14 11:52:03 UTC
README
此包提供文件监视器。
安装
当前版本仅支持 fswatch,因此您需要先安装 fswatch。
# 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
希望构建 fswatch 的用户应获取一个 tarball 释放版。
然后,确保您已安装 PHP 的 swoole 扩展。
pecl install swoole
最后,您可以通过 Composer 安装 Swoole Watcher
composer require huang-yi/swoole-watcher
使用方法
创建您的监视器脚本如下
<?php require __DIR__ . '/vendor/autoload.php'; use HuangYi\Watcher\Commands\Fswatch; use HuangYi\Watcher\Watcher; $command = new Fswatch('/watched/path'); $command->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();
许可证
Swoole Watcher 是开源软件,许可协议为 MIT 许可证。