PHPackages                             brunonatali/inotify - 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. brunonatali/inotify

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

brunonatali/inotify
===================

A react PHP implementation for inotify, an filesystem change monitor

v0.1.1(5y ago)036MITPHPPHP &gt;=7

Since Jan 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/brunonatali/inotify)[ Packagist](https://packagist.org/packages/brunonatali/inotify)[ RSS](/packages/brunonatali-inotify/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Inotify
=======

[](#inotify)

Inotify is a filesystem monitor event based. This lib aim to be file change notification within PHP React.

**Table of Contents**

- [Before start](#before-start)
- [Quickstart example](#quickstart-example)
- [Register / Deregister](#de-register)
    - [add()](#add-f)
    - [remove()](#remove-f)
    - [stopAll()](#stopall-f)
    - [Events](#events)
- [General](#general)
    - [getAll()](#getall-f)
    - [getLastError()](#lasterror-f)
- [Supported flags](#flags)
- [Install](#install)
- [License](#license)

Before start
------------

[](#before-start)

BEFORE BEGIN - You must install [inotify extension](https://www.php.net/manual/en/inotify.install.php) to make this library work.
After installation, you must place new extension config to your php.ini file, if extension was not declared, system will try to load automatically (using [dl()](https://www.php.net/manual/en/function.dl.php)) and throws an exception if was unable to proceed.
Follow quickstart example and use try-catch method to build this class.

Quickstart example
------------------

[](#quickstart-example)

```
use BrunoNatali\Inotify\Factory;
use React\EventLoop\Factory as LoopFactory;

$loop = LoopFactory::create();
try {
    $notify = new Factory($loop);
} catch ($e \Exception) {
    /**
     * Exception codes:
     * EXCEPTION_EXTENSION_LOAD -> Extension is not loaded
     * EXCEPTION_EXTENSION_INIT -> inotify initialization error
    */
}

$filePathName = __FILE__;

$notify->add($filePathName, IN_ATTRIB);
$notify->on(IN_ATTRIB, function () {
	echo "File touched";
});
```

Register / Deregister
---------------------

[](#register--deregister)

This lib is driven by Événement and so after add() you must register an [event](#events) to catch.
Follow to the next functions and examples.

### add()

[](#add)

To start watch some file, just call add(string $fileName, int [$flags](#flags)) :

```
$notify->add('/some/path/file.name', IN_ATTRIB | IN_MODIFY | IN_ACCESS);
```

Note. You can concatenate flags as exaple above.
Returns true if sucessfully added

### remove()

[](#remove)

The remove way is simple as add

```
$notify->remove('/some/path/file.name');
```

Returns true if removed or not exists

### stopAll()

[](#stopall)

This will remove() all watchers.
This function needs no parmans an returns nothing
Note. Additionaly you can call [getAll()](#getall-f) and stop one by one.

### Events

[](#events)

To receive any registered event you must register usin on([FLAG\_NAME](#flags), callable):

```
$notify->on(FLAG_NAME, function () {
	// Do some stuff
});
```

If you plan to get noticed when any mask was triggered, use "all" (lowercase) as FLAG\_NAME.

After registered, when watcher fires an event program will call your function. Ex.

```
$notify->add('/some/path/file.name', IN_ATTRIB | IN_MODIFY | IN_ACCESS);
$notify->on(IN_ACCESS, function () {
	echo "My file was accessed"
});
```

And this will fire access event causing your code to telling you that file was accessed:

```
cat /some/path/file.name > /dev/null
```

General
-------

[](#general)

### getAll()

[](#getall)

Returns an array containing all registered files to watch in this structure:

```
[
    "somepathfile.name" => (int) unique inotify instance wide watch descriptor,
    "otherpathfile.ext" => (int) another unique inotify instance
]
```

### getLastError()

[](#getlasterror)

In most of cases, this functions, will not throw an exception, but will return false. To let you best track the reson why fail to do something this lib will provide textual error, just call getLastError() right after failure.

Supported flags
---------------

[](#supported-flags)

Some function explained above needs flag to tell them when trigger an event or how to handle triggered event.
This flags was called by developer as constants and originally posted [here](https://www.php.net/manual/en/inotify.constants.php).
If you want to know its value, follow this list:
IN\_ACCESS = 1
IN\_MODIFY = 2
IN\_ATTRIB = 4
IN\_CLOSE\_WRITE = 8
IN\_CLOSE\_NOWRITE = 16
IN\_OPEN = 32
IN\_MOVED\_FROM = 64
IN\_MOVED\_TO = 128
IN\_CREATE = 256
IN\_DELETE = 512
IN\_DELETE\_SELF = 1024
IN\_MOVE\_SELF = 2048
IN\_UNMOUNT = 8192
IN\_Q\_OVERFLOW = 16384
IN\_IGNORED = 32768
IN\_CLOSE = 24
IN\_MOVE = 192
IN\_ALL\_EVENTS = 4095
IN\_ONLYDIR = 16777216
IN\_DONT\_FOLLOW = 33554432
IN\_MASK\_ADD = 536870912
IN\_ISDIR = 1073741824
IN\_ONESHOT = 4294967295

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This project follows [SemVer](https://semver.org/). This will install the latest supported version:

```
$ composer require brunonatali/inotify:^0.1
```

This project aims to run on Linux and require [inotify PHP extensions](https://pecl.php.net/package/inotify), but actually not tested in all environments. If you find a bug, please report.

License
-------

[](#license)

MIT, see [LICENSE file](LICENSE).

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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 ~5 days

Total

2

Last Release

1931d ago

### Community

Maintainers

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

---

Top Contributors

[![brunonatali](https://avatars.githubusercontent.com/u/28903793?v=4)](https://github.com/brunonatali "brunonatali (6 commits)")

---

Tags

filesystemeventloopreactinotify

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brunonatali-inotify/health.svg)

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.1k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M787](/packages/league-flysystem-aws-s3-v3)[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

72528.6M91](/packages/knplabs-knp-gaufrette-bundle)[league/flysystem-local

Local filesystem adapter for Flysystem.

226231.8M39](/packages/league-flysystem-local)[oneup/flysystem-bundle

Integrates Flysystem filesystem abstraction library to your Symfony project.

64422.9M65](/packages/oneup-flysystem-bundle)

PHPackages © 2026

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