PHPackages                             allejo/resource-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. allejo/resource-watcher

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

allejo/resource-watcher
=======================

Simple PHP resource watcher library - no Laravel dependencies

v1.0.1(9y ago)4245BSD-2-ClausePHPPHP &gt;=5.3.0

Since Feb 13Pushed 9y ago1 watchersCompare

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

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

Resource Watcher
================

[](#resource-watcher)

A resource watcher allows you to watch a resource for any changes. This means you can watch a directory and then listen for any changes to files within that directory or to the directory itself.

This is a fork of [Jason Lewis's project](https://github.com/jasonlewis/resource-watcher) without Laravel dependencies and uses the Symfony Filesystem instead. This fork is intended to be used for those who do not want to add yet another Filesystem object from another project.

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

[](#installation)

Use composer to add this project as a dependency.

```
composer require allejo/resource-watcher

```

Usage
-----

[](#usage)

The Resource Watcher is best used from a console. An example of a console command can be found in the `watcher` file. This file is commented to give you an idea of how to configure and use a resource watcher. Once you've customized the command to your liking you can run it from your console.

```
$ php watcher

```

Any changes you make to the resource will be outputted to the console.

Quick Overview
--------------

[](#quick-overview)

To watch resources you first need an instance of `JasonLewis\ResourceWatcher\Watcher`. This class has a few dependencies (`JasonLewis\ResourceWatcher\Tracker` and `Symfony\Component\Filesystem\Filesystem`) that must also be instantiated.

```
$files = new Symfony\Component\Filesystem\Filesystem;
$tracker = new JasonLewis\ResourceWatcher\Tracker;

$watcher = new JasonLewis\ResourceWatcher\Watcher($tracker, $files);
```

Now that we have our watcher we can create a listener for a given resource.

```
$listener = $watcher->watch('path/to/resource');
```

When you watch a resource an instance of `JasonLewis\ResourceWatcher\Listener` is returned. With this we can now listen for certain events on a resource.

There are three events we can listen for: `modify`, `create`, and `delete`. The callback you give to the listener receives two parameters, the first being an implementation of `JasonLewis\ResourceWatcher\Resource\ResourceInterface` and the second being the absolute path to the resource.

```
$listener->modify(function($resource, $path) {
    echo "{$path} has been modified.".PHP_EOL;
});
```

You can use the alias methods as well.

```
$listener->onModify(function($resource, $path) {
    echo "{$path} has been modified.".PHP_EOL;
});
```

You can also listen for any of these events. This time the callback receives a different set of parameters, the first being an instance of `JasonLewis\ResourceWatcher\Event` and the remaining two being the same as before.

```
$listener->anything(function($event, $resource, $path) {

});
```

> Remember that each call to `$watcher->watch()` will return an instance of `JasonLewis\ResourceWatcher\Listener`, so be sure you attach listeners to the right one!

Once you're watching some resources and have your listeners set up you can start the watching process.

```
$watcher->start();
```

By default the watcher will poll for changes every second. You can adjust this by passing in an optional first parameter to the `start` method. The polling interval is given in microseconds, so 1,000,000 microseconds is 1 second. The watch will continue until such time that it's aborted from the console. To set a timeout pass in the number of microseconds before the watch will abort as the second parameter.

The `start` method can also be given a callback as an optional third parameter. This callback will be fired before checking for any changes to resources.

```
$watcher->start(1000000, null, function($watcher) {
	// Perhaps perform some other check and then stop the watch.
	$watcher->stop();
});
```

License
-------

[](#license)

Resource Watcher is released under the 2-clause BSD license. See the `LICENSE` for more details.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80.6% 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

3418d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1246453?v=4)[Vladimir Jimenez](/maintainers/allejo)[@allejo](https://github.com/allejo)

---

Top Contributors

[![jasonlewis](https://avatars.githubusercontent.com/u/829059?v=4)](https://github.com/jasonlewis "jasonlewis (54 commits)")[![allejo](https://avatars.githubusercontent.com/u/1246453?v=4)](https://github.com/allejo "allejo (8 commits)")[![assertchris](https://avatars.githubusercontent.com/u/200609?v=4)](https://github.com/assertchris "assertchris (2 commits)")[![bencorlett](https://avatars.githubusercontent.com/u/181919?v=4)](https://github.com/bencorlett "bencorlett (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![suwardany](https://avatars.githubusercontent.com/u/2053770?v=4)](https://github.com/suwardany "suwardany (1 commits)")

---

Tags

symfonyresourceassets

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1668.1M217](/packages/symfony-asset-mapper)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

101466.4k45](/packages/friendsoftypo3-content-blocks)[jasonlewis/resource-watcher

Simple PHP resource watcher library.

221146.1k14](/packages/jasonlewis-resource-watcher)[bref/symfony-bridge

Makes Symfony work on AWS Lambda with Bref

501.9M8](/packages/bref-symfony-bridge)[maba/webpack-bundle

Bundle to Integrate Webpack to Symfony

122268.3k4](/packages/maba-webpack-bundle)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

57133.6k3](/packages/sensiolabs-minify-bundle)

PHPackages © 2026

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