PHPackages                             wuguangping/file-watcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. wuguangping/file-watcher

ActiveLibrary[File &amp; Storage](/categories/file-storage)

wuguangping/file-watcher
========================

3.7.1(1y ago)02Apache-2.0PHP

Since Dec 8Pushed 1y agoCompare

[ Source](https://github.com/wuguangping/file-watcher)[ Packagist](https://packagist.org/packages/wuguangping/file-watcher)[ RSS](/packages/wuguangping-file-watcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

file-watcher
============

[](#file-watcher)

使用规则
----

[](#使用规则)

### WatchRule

[](#watchrule)

监控目录:

```
$watchRule = new \EasySwoole\FileWatcher\WatchRule(EASYSWOOLE_ROOT."/App");
```

指定忽略目录：

```
/**@var \EasySwoole\FileWatcher\WatchRule $watchRule **/
$watchRule->setIgnorePaths([EASYSWOOLE_ROOT."/App/Api", EASYSWOOLE_ROOT."/App/Admin"]);
```

指定忽略文件：

```
/**@var \EasySwoole\FileWatcher\WatchRule $watchRule **/
$watchRule->setIgnoreFiles([EASYSWOOLE_ROOT."/App/Api/Teacher.php", EASYSWOOLE_ROOT."/App/Admin/Teacher.php"]);
```

指定匹配后缀：

```
/**@var \EasySwoole\FileWatcher\WatchRule $watchRule **/
$watchRule->setType($watchRule::SCAN_TYPE_SUFFIX_MATCH);
//$watchRule->setType($watchRule::SCAN_TYPE_IGNORE_SUFFIX);
$watchRule->setSuffix(['php']);
```

> type为SCAN\_TYPE\_SUFFIX\_MATCH时，只匹配后缀必须在suffix规则数组的文件。 type为SCAN\_TYPE\_IGNORE\_SUFFIX时，会忽略掉后缀在suffix规则数组的文件。

### FileWatcher

[](#filewatcher)

设置监控程序:

```
$fileWatcher = new \EasySwoole\FileWatcher\FileWatcher();
$fileWatcher->setScannerDriver(\EasySwoole\FileWatcher\Scanner\Inotify::class);
$fileWatcher->setScannerDriver(\EasySwoole\FileWatcher\Scanner\FileScanner::class);
```

> 二选一 不调用此方法 存在inotify扩展默认为Inotify::class反之FileScanner::class

增加监控规则：

```
/**@var \EasySwoole\FileWatcher\FileWatcher $fileWatcher **/
$fileWatcher->addRule(new \EasySwoole\FileWatcher\WatchRule(__DIR__));
$fileWatcher->addRule(new \EasySwoole\FileWatcher\WatchRule(EASYSWOOLE_ROOT. '/App'));
```

> 可进行多次调用 对不同目录设置不同的规则

设置异常回调：

```
/**@var \EasySwoole\FileWatcher\FileWatcher $fileWatcher **/
$fileWatcher->setOnException(function (\Throwable $throwable){

});
```

设置检测周期(默认`1000ms`)：

```
/**@var \EasySwoole\FileWatcher\FileWatcher $fileWatcher **/
$fileWatcher->setCheckInterval(1000);
```

设置触发回调(文件有变化)：

```
/**@var \EasySwoole\FileWatcher\FileWatcher $fileWatcher **/
$fileWatcher->setOnChange(function (array $list, \EasySwoole\FileWatcher\WatchRule $rule){
    // list为变化的文件列表
});
```

启动(swoole服务中使用)：

```
/**@var \EasySwoole\FileWatcher\FileWatcher $fileWatcher **/
/**@var \Swoole\Server $server **/
$fileWatcher->attachServer($server);
```

EasySwoole中用于热重启
----------------

[](#easyswoole中用于热重启)

例如在`Easyswoole`开发模式中，我们希望当有代码变动的时候，实现Server重启，示例代码如下：

```
namespace EasySwoole\EasySwoole;

use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\FileWatcher\FileWatcher;
use EasySwoole\FileWatcher\WatchRule;

class EasySwooleEvent implements Event
{
    public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');
    }

    public static function mainServerCreate(EventRegister $register)
    {
        $watcher = new FileWatcher();
        $rule = new WatchRule(EASYSWOOLE_ROOT."/App");
        $watcher->addRule($rule);
        $watcher->setOnChange(function (){
            Logger::getInstance()->info('file change ,reload!!!');
            ServerManager::getInstance()->getSwooleServer()->reload();
        });
        $watcher->attachServer(ServerManager::getInstance()->getSwooleServer());
    }
}
```

> 注意，reload仅仅针对Worker进程加载的代码有效

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance43

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~764 days

Total

3

Last Release

450d ago

Major Versions

1.0.1 → 3.7.12025-02-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0011c06a2a578f7815c289036f5d06d0fe34c571338bd0e8fe57565da69779b?d=identicon)[wuguangping](/maintainers/wuguangping)

---

Top Contributors

[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (9 commits)")[![Player626](https://avatars.githubusercontent.com/u/44792981?v=4)](https://github.com/Player626 "Player626 (4 commits)")[![wuguangping](https://avatars.githubusercontent.com/u/7068986?v=4)](https://github.com/wuguangping "wuguangping (2 commits)")[![XueSiLf](https://avatars.githubusercontent.com/u/31389659?v=4)](https://github.com/XueSiLf "XueSiLf (1 commits)")

### Embed Badge

![Health badge](/badges/wuguangping-file-watcher/health.svg)

```
[![Health](https://phpackages.com/badges/wuguangping-file-watcher/health.svg)](https://phpackages.com/packages/wuguangping-file-watcher)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M123](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M61](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
