penguin / fswatch
Library for monitoring file changes with fswatch
Installs: 52
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/penguin/fswatch
Requires
- php: ^8.1
- symfony/process: ^6.1
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-10-16 19:07:32 UTC
README
This package provides a file watcher.
Installation
The current version only supports fswatch, so you'll have to install fswatch first.
# MacOS brew install fswatch # Linux wget https://github.com/emcrisostomo/fswatch/releases/download/{VERSION}/fswatch-{VERSION}.tar.gz tar -xzvf fswatch-{VERSION}.tar.gz cd fswatch-{VERSION} && ./configure && make && sudo make install && sudo ldconfig # Composer composer require penguin/fswatch
Usage
<?php use Penguin\Component\FsWatch\FsWatch; require __DIR__ . '/vendor/autoload.php'; (new FsWatch(__DIR__)) ->usePolling() // use poll_monitor (default is inotify in Linux, FSEvents in MacOS) // ignore files json, txt with regex ->ignore('.*\.json') ->ignore('.*\.txt') ->onChange(function (string $path) { echo "onChange {$path}"; });
Methods
onChange(callable $callback(string $path, Process $process))onAdd(callable $callback(string $path, Process $process))onUnlink(callable $callback(string $path, Process $process))onAddDir(callable $callback(string $path, Process $process))onError(callable $callback, Process $process)onAny(callable $callback(int $eventCode, string $path, Process $process)): Event will be executed when no other event is registeredusePolling(): Use poll monitor. The poll monitor, available on any platform, only relies on available CPU and memory to perform its task.oneEvent(): Exit fswatch after the first set of events is receivedmultiEvent(): Don't exit fswatch after events is receivedignore(string $regex): Exclude paths matching regexunWatch(string ...$paths)addWatch(string ...$paths)