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

ActiveLibrary

letuananh1873/resource-watcher
==============================

Simple PHP resource watcher library.

v1.2.0(10y ago)03PHPPHP &gt;=5.3.0

Since Feb 7Pushed 6y agoCompare

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

READMEChangelogDependencies (3)Versions (7)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.

[![Build Status](https://camo.githubusercontent.com/a8d88353f5479f0e192f4983d30a7047eaeff56f73603f460efb7d3da589f2db/68747470733a2f2f7472617669732d63692e6f72672f6a61736f6e6c657769732f7265736f757263652d776174636865722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jasonlewis/resource-watcher)

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

[](#installation)

To install Resource Watcher add it to the `requires` key of your `composer.json` file.

```
"jasonlewis/resource-watcher": "1.2.*"

```

Then update your project with `composer update`.

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 `Illuminate\Filesystem\Filesystem`) that must also be instantiated.

```
$files = new Illuminate\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();
});
```

Framework Integration
---------------------

[](#framework-integration)

### Laravel 4 and Laravel 5

[](#laravel-4-and-laravel-5)

Included is a service provider for the Laravel framework. This service provider will bind an instance of `JasonLewis\ResourceWatcher\Watcher` to the application container under the `watcher` key.

Register `JasonLewis\ResourceWatcher\Integration\LaravelServiceProvider` in the array of providers in `app/config/app.php`.

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

// Or if you don't have access to an instance of the application container.
$listener = app('watcher')->watch('path/to/resource');
```

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 85.9% 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 ~176 days

Recently: every ~163 days

Total

6

Last Release

3961d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17105919?v=4)[letuananh1873](/maintainers/letuananh1873)[@letuananh1873](https://github.com/letuananh1873)

---

Top Contributors

[![jasonlewis](https://avatars.githubusercontent.com/u/829059?v=4)](https://github.com/jasonlewis "jasonlewis (55 commits)")[![letuananh1873](https://avatars.githubusercontent.com/u/17105919?v=4)](https://github.com/letuananh1873 "letuananh1873 (3 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)")[![furey](https://avatars.githubusercontent.com/u/1914481?v=4)](https://github.com/furey "furey (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

laravelresourceassets

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[laravel/ui

Laravel UI utilities and presets.

2.7k134.9M601](/packages/laravel-ui)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[jasonlewis/resource-watcher

Simple PHP resource watcher library.

221145.8k14](/packages/jasonlewis-resource-watcher)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)

PHPackages © 2026

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