crodas/watch-files

Watch files and directories for changes

Maintainers

👁 crodas

Package info

github.com/crodas/WatchFiles

pkg:composer/crodas/watch-files

Statistics

Installs: 5 897

Dependents: 7

Suggesters: 0

Stars: 9

Open Issues: 0

v0.1.9 2016-08-18 04:46 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-4-Clause a50ba544263b6f3673a2f10d2746e1307e722267

  • César D. Rodas <crodas.woop@php.net>

This package is auto-updated.

Last update: 2026-06-12 22:39:04 UTC


README

Stateless way of watching files and directory for changes.

It is useful when you compile files, and you would like a simple and efficient way of watching files and directories for changes to avoid re-compilation.

How to install

You can install it using composer.

composer require crodas/watch-files *

How to use it

require "vendor/autoload.php";

use WatchFiles\Watch;

// we'd like to watch some files
// and to save its state in foobar.php
$foobar = new Watch("foobar.php");
if ($foobar->isWatching()) {
 if (!$foobar->hasChanged()) {
 // somebody else before us started watching files/dirs
 // on foobar.php and *nothing* changed since last 
 // time
 return;
 }
 // do heavy stuff here (Recompile it?)
 // we need to tell the watch that we're aware of lastest
 // changes and we'd like to update the file modification time
 $foobar->rebuild();
 return;
}

// we'd love to see when a new file has been added or deleted
$foobar->watchDir("foodir");
$foobar->watchDirs(array("foodir", 'foobar'));

// or monitor changes inside file or files
$foobar->watchFile("foodir.php");
$foobar->watchFiles(array("foodir.php", 'foobar.php'));

// start watching!
$foobar->watch();