PHPackages                             phprtc/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phprtc/watcher

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phprtc/watcher
==============

Swoole File Watcher

0.1.3(3y ago)834253[3 issues](https://github.com/phprtc/watcher/issues)1MITPHPPHP ^8.1

Since Mar 5Pushed 3y ago3 watchersCompare

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

READMEChangelog (6)Dependencies (5)Versions (11)Used By (1)

File Watcher
============

[](#file-watcher)

PHP-based file system changes watcher implemented using [**Swoole**](https://swoole.co.uk) &amp; **Inotify**.

Installation
------------

[](#installation)

```
composer require phprtc/watcher ^0.1 --dev

```

Usage
-----

[](#usage)

#### Basic Usage

[](#basic-usage)

```
use RTC\Watcher\Watcher;
use RTC\Watcher\Watching\EventInfo;

require 'vendor/autoload.php';

Watcher::create()
    ->addPath(__DIR__ . '/app')
    ->addPath(__DIR__ . '/views')
    ->onChange(function (EventInfo $eventInfo) {
        echo $eventInfo->getWatchedItem()->getFullPath() . PHP_EOL;
    })
    ->watch();
```

#### Any Event

[](#any-event)

Listens to any event on given path

Be careful using this method.

```
use RTC\Watcher\Watcher;
use RTC\Watcher\Watching\EventInfo;

require 'vendor/autoload.php';

Watcher::create()
    ->addPath(__DIR__ . '/app')
    ->onAny(function (EventInfo $eventInfo) {
        echo date('H:i:s') . " - {$eventInfo->getName()} {$eventInfo->getWatchedItem()->getFullPath()}\n";
    })
    ->watch();
```

#### Ignoring Path

[](#ignoring-path)

Ignore files using regular expression

```
use RTC\Watcher\Watcher;
use RTC\Watcher\Watching\EventInfo;

require 'vendor/autoload.php';

Watcher::create()
    ->addPath(__DIR__ . '/app')
    ->ignore(__DIR__ . '/test1/t/*')   // Ignore files in "/test1/t/"
    ->ignore([
        __DIR__ . '/test1/t/.*(\.php$)',   // Ignore files that end with "php" in "/test1/t/"
        __DIR__ . '/test1/t/.*(\.js)',   // Ignore files that end with "js" in "/test1/t/"
    ])
    ->onChange(function (EventInfo $eventInfo) {
        echo date('H:i:s') . " - {$eventInfo->getName()} {$eventInfo->getWatchedItem()->getFullPath()}\n";
    })
    ->watch();
```

#### Filter

[](#filter)

- Make sure that the file whose event is being fired should not end with provided characters.

    ```
    use RTC\Watcher\Watcher;
    use RTC\Watcher\Watching\EventInfo;

    require 'vendor/autoload.php';

    Watcher::create()
        ->addPath(__DIR__ . '/app')
        ->fileShouldNotEndWith(['.php'])
        ->onChange(function (EventInfo $eventInfo) {
            echo $eventInfo->getWatchedItem()->getFullPath() . PHP_EOL;
        })
        ->watch();
    ```
- Only listen to event with file name that matches given extension(s).

    ```
    use RTC\Watcher\Watcher;
    use RTC\Watcher\Watching\EventInfo;

    require 'vendor/autoload.php';

    Watcher::create()
        ->addPath(__DIR__ . '/app')
        ->addExtension('php')
        ->onChange(function (EventInfo $eventInfo) {
            echo $eventInfo->getWatchedItem()->getFullPath() . PHP_EOL;
        })
        ->watch();
    ```

#### Stopping Watcher

[](#stopping-watcher)

```
use RTC\Watcher\Watcher;
use RTC\Watcher\Watching\EventInfo;
use Swoole\Timer;

require 'vendor/autoload.php';

$watcher = Watcher::create()
    ->addPath(__DIR__)
    ->onCreate(function (EventInfo $eventInfo) {
        echo date('H:i:s') . ": CREATED  - {$eventInfo->getWatchedItem()->getFullPath()}\n";
    });

Timer::after(1000, fn() => $watcher->stop());   // Stop watching after 1 second

$watcher->start();

touch(__DIR__ . '/auto-created.txt');
unlink(__DIR__ . '/auto-created.txt');
```

#### Swoole Server Integration

[](#swoole-server-integration)

```
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;
use RTC\Watcher\Watcher;

require 'vendor/autoload.php';

$server = new Server('0.0.0.0', 9000);
$server->on('request', function (Request $request, Response $response) {
    $response->end('Hello world');
});

$server->on('start', function (Server $server) {
    echo "Server started at http://0.0.0.0:9000\n";

    Watcher::create()
        ->addPath(__DIR__ . '/app')
        ->addPath(__DIR__ . '/views')
        ->onChange(fn() => $server->reload())
        ->watch();
});

$server->start();
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~76 days

Recently: every ~95 days

Total

6

Last Release

1152d ago

### Community

Maintainers

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

---

Top Contributors

[![Ahmard](https://avatars.githubusercontent.com/u/44737217?v=4)](https://github.com/Ahmard "Ahmard (33 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[react/stream

Event-driven readable and writable streams for non-blocking I/O in ReactPHP

688126.8M194](/packages/react-stream)[react/child-process

Event-driven library for executing child processes with ReactPHP.

34076.1M136](/packages/react-child-process)[alchemy/binary-driver

A set of tools to build binary drivers

19110.9M39](/packages/alchemy-binary-driver)[react/zmq

ZeroMQ bindings for React.

2471.7M31](/packages/react-zmq)[mkraemer/react-pcntl

PCNTL bindings for ReactPHP

57289.0k9](/packages/mkraemer-react-pcntl)[wyrihaximus/react-child-process-pool

Pool wyrihaximus/react-child-process-messenger processes

40244.4k5](/packages/wyrihaximus-react-child-process-pool)

PHPackages © 2026

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