PHPackages                             myvon/reactphp-file-system-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. myvon/reactphp-file-system-watcher

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

myvon/reactphp-file-system-watcher
==================================

File System Watcher made with ReactPHP EventLoop and ChildProcess

1.0(3y ago)21.3k↓80%MITPHP

Since Feb 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/myvon/reactphp-file-system-watcher)[ Packagist](https://packagist.org/packages/myvon/reactphp-file-system-watcher)[ RSS](/packages/myvon-reactphp-file-system-watcher/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

reactphp-file-system-watcher
============================

[](#reactphp-file-system-watcher)

File System Watcher made with ReactPHP EventLoop and ChildProcess.

This is entirely based on [spatie/file-system-watcher](https://github.com/spatie/file-system-watcher) and adapted from [symfony/process](https://github.com/symfony/process) to [react/child-process](https://github.com/reactphp/child-process)

[![Latest Version on Packagist](https://camo.githubusercontent.com/872e68dafe2933c1257f30ece0f1408983c5435075aa2b1d0cd65472a8fb2e40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d79766f6e2f72656163747068702d66696c652d73797374656d2d776174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/myvon/reactphp-file-system-watcher)[![Tests](https://github.com/myvon/reactphp-file-system-watcher/actions/workflows/run-test.yml/badge.svg)](https://github.com/myvon/reactphp-file-system-watcher/actions/workflows/run-test.yml)[![Total Downloads](https://camo.githubusercontent.com/ce09aa59216de6147605e3face8cc035527a63f2a5e7ea7d0de6f518b87cc5c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d79766f6e2f72656163747068702d66696c652d73797374656d2d776174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packagesmyvon/reactphp-file-system-watcher)

Watch changes in the file system using PHP
==========================================

[](#watch-changes-in-the-file-system-using-php)

This package allows you to react to all kinds of changes in the file system.

It use [react/event-loop](https://github.com/reactphp/event-loop) and [react/child-process](https://github.com/reactphp/child-process) to run without blocking the rest of your code (see [ReactPHP](https://reactphp.org/) for more information).

Here's how you can run code when a new file gets added.

```
use Myvon\Watcher\Watch;

Watch::path($directory)
    ->onFileCreated(function (string $newFilePath) {
        // do something...
    })
    ->start();
```

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

[](#installation)

You can install the package via composer:

```
composer require myvon/reactphp-file-system-watcher
```

In your project, you should have the JavaScript package [`chokidar`](https://github.com/paulmillr/chokidar) installed. You can install it via npm

```
npm install chokidar
```

or Yarn

```
yarn add chokidar
```

Usage
-----

[](#usage)

Here's how you can start watching a directory and get notified of any changes.

```
use Myvon\Watcher\Watch;

$watcher = Watch::path($directory)
    ->onAnyChange(function (string $type, string $path) {
        if ($type === Watch::EVENT_TYPE_FILE_CREATED) {
            echo "file {$path} was created";
        }
    })
    ->start();
```

You can pass as many directories as you like to `path`.

To start watching, call the `start` method.

To make sure that the watcher keeps watching in production, monitor the script or command that starts it with something like [Supervisord](http://supervisord.org).

### Detected the type of change

[](#detected-the-type-of-change)

The `$type` parameter of the closure you pass to `onAnyChange` can contain one of these values:

- `Watcher::EVENT_TYPE_FILE_CREATED`: a file was created
- `Watcher::EVENT_TYPE_FILE_UPDATED`: a file was updated
- `Watcher::EVENT_TYPE_FILE_DELETED`: a file was deleted
- `Watcher::EVENT_TYPE_DIRECTORY_CREATED`: a directory was created
- `Watcher::EVENT_TYPE_DIRECTORY_DELETED`: a directory was deleted

### Listening for specific events

[](#listening-for-specific-events)

To handle file systems events of a certain type, you can make use of dedicated functions. Here's how you would listen for file creations only.

```
use Myvon\Watcher\Watch;

Watch::path($directory)
    ->onFileCreated(function (string $newFilePath) {
        // do something...
    });
```

These are the related available methods:

- `onFileCreated()`: accepts a closure that will get passed the new file path
- `onFileUpdated()`: accepts a closure that will get passed the updated file path
- `onFileDeleted()`: accepts a closure that will get passed the deleted file path
- `onDirectoryCreated()`: accepts a closure that will get passed the created directory path
- `onDirectoryDeleted()`: accepts a closure that will get passed the deleted directory path
- `onClose()`: accepts a closure that will be called when watcher is stopped

### Watching multiple paths

[](#watching-multiple-paths)

You can pass multiple paths to the `paths` method.

```
use Myvon\Watcher\Watch;

Watch::paths($directory, $anotherDirectory);
```

### Performing multiple tasks

[](#performing-multiple-tasks)

You can call `onAnyChange`, 'onFileCreated', ... multiple times. All given closures will be performed

```
use Myvon\Watcher\Watch;

Watch::path($directory)
    ->onFileCreated(function (string $newFilePath) {
        // do something on file creation...
    })
    ->onFileCreated(function (string $newFilePath) {
        // do something else on file creation...
    })
    ->onAnyChange(function (string $type, string $path) {
        // do something...
    })
    ->onAnyChange(function (string $type, string $path) {
        // do something else...
    })
    // ...
```

### Stopping the watcher gracefully

[](#stopping-the-watcher-gracefully)

By default, the watcher will continue indefinitely when started. There is two ways to gracefully stop the watcher :

- you can call `shouldContinue` and pass it a closure. If the closure returns a falsy value, the watcher will stop. The given closure will be executed every 0.5 second.

```
use Myvon\Watcher\Watch;

Watch::path($directory)
    ->shouldContinue(function () {
        // return true or false
    })
    // ...
```

- you can call the `stop` method anywhere in your code

```
use Myvon\Watcher\Watch;

$watcher = Watch::path($directory);
// ...
$watcher->stop();
```

### Change the speed of watcher

[](#change-the-speed-of-watcher)

By default, the changes are tracked every 0.5 seconds, however you could change that.

```
use Myvon\Watcher\Watch;

Watch::path($directory)
    ->setIntervalTime(0.1) //unit is seconds therefore -> 0.1s
    // ...rest of your methods
```

You can also specify the interval directly on the `start`.

```
use Myvon\Watcher\Watch;

Watch::path($directory)
    ->start(null, 0.1); //unit is seconds therefore -> 0.1s
    // ...rest of your methods
```

### Using another loop

[](#using-another-loop)

By default, the watcher will use the default loop by calling `Loop:get()`. If needed, you can use another loop implemting `LoopInterface` interface of ReactPHP by passing it as the first argument of `start`:

```
use Myvon\Watcher\Watch;

$loop = new MyCustomLoop();

Watch::path($directory)
    ->start($loop);
```

Notice: the watcher will register the needed timer but won't start the loop, don't forget to start it.

You also can look into `test/WatchTest.php` to see how it is used to have one loop by test

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/myvon/reactphp-file-system-watcher/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- All credits goes to [Spatie](https://github.com/spatie) for the original [spatie/file-system-watcher](https://github.com/spatie/file-system-watcher) library

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

1226d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/954447d10f755d5a91a6a68ed467ea6173512d3d9b57e99d2ff34bd1e61ec215?d=identicon)[myvon](/maintainers/myvon)

---

Top Contributors

[![myvon](https://avatars.githubusercontent.com/u/16448032?v=4)](https://github.com/myvon "myvon (5 commits)")

---

Tags

reactphpfile-system-watchermyvonreactphp-file-system-watcher

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/myvon-reactphp-file-system-watcher/health.svg)

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

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k245.4M23.9k](/packages/friendsofphp-php-cs-fixer)[spatie/file-system-watcher

Watch changes in the file system using PHP

2502.6M21](/packages/spatie-file-system-watcher)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k406.5k25](/packages/team-reflex-discord-php)[clue/reactphp-sqlite

Async SQLite database, lightweight non-blocking process wrapper around file-based database extension (ext-sqlite3), built on top of ReactPHP.

5741.6k19](/packages/clue-reactphp-sqlite)[clue/reactphp-ssh-proxy

Async SSH proxy connector and forwarder, tunnel any TCP/IP-based protocol through an SSH server, built on top of ReactPHP

2115.1k5](/packages/clue-reactphp-ssh-proxy)[clue/shell-react

Run async commands within any interactive shell command, built on top of ReactPHP.

332.1k](/packages/clue-shell-react)

PHPackages © 2026

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