concerto/directory-monitor

使用 Inotify 监听目录变化的库。

安装: 716

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 3

分支: 1

类型:concerto-component

v0.1 2014-05-02 10:56 UTC

This package is not auto-updated.

Last update: 2020-08-07 17:58:27 UTC


README

使用 Inotify 监听目录变化的库。

Build Status

安装

安装 Directory Monitor 的推荐方法是 通过 composer

{
    "require": {
        "concerto/directory-monitor": "0.*"
    }
}

使用方法

创建一个 RecursiveMonitor 实例并监听所需的 events

use Concerto\DirectoryMonitor\RecursiveMonitor;
use React\EventLoop\Factory as EventLoopFactory;

$loop = EventLoopFactory::create();
$monitor = new RecursiveMonitor($loop, __DIR__);

// Fired on any Inotify event:
$monitor->on('notice', function($path, $root) {
	echo "Notice: {$path} in {$root}\n";
});

$monitor->on('create', function($path, $root) {
	echo "Created: {$path} in {$root}\n";
});

$monitor->on('delete', function($path, $root) {
	echo "Deleted: {$path} in {$root}\n";
});

$monitor->on('modify', function($path, $root) {
	echo "Modified: {$path} in {$root}\n";
});

$monitor->on('write', function($path, $root) {
	echo "Wrote: {$path} in {$root}\n";
});

$loop->run();

您也可以使用正则表达式忽略文件

// Ignore hidden files:
$monitor->ignore('/\.');

// Ignore the temp folder:
$monitor->ignore('^/tmp');

// Ignore all .cache files:
$monitor->ignore('\.cache$');

您还可以注意到之前被忽略的文件

// Notice compiled templates:
$monitor->notice('^/tmp/templates');

表达式应用于相对于被监控根目录的每个项目的完整路径。例如,如果您的目录是 /root/path 并且一个事件是由 /root/path/some/file 触发的,那么表达式将针对路径 /some/file 执行。