Skip to content

jefyokta/php-file-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP File Watcher

Lightweight, cross-platform file watcher for Linux and macOS using native OS facilities (inotify on Linux, kqueue on macOS), exposed via PHP FFI.


Requirements

  • Operating System: Linux or macOS
  • PHP: FFI extension enabled (--enable-ffi or ffi.enable=1 in php.ini)
  • Composer: for installation and autoloading

Installation

Install the package via Composer:

composer require jefyokta/php-file-watcher

Usage

use Jefyokta\PhpFileWatcher\Watcher;

Watcher::onChange(function(string $file) {
    echo "File Changed: $file\n";
})->watch(__DIR__);
  • onChange(callable $callback) — Register a callback to be invoked on each changed file.
  • watch(string $directory) — Start watching the specified directory recursively.

Notes

  • This package relies on PHP's FFI and a compiled native library (libfilewatcher.so or .dylib), so ensure the native library is built for your platform.
  • Recursive watching of directories is supported.
  • Suitable for lightweight monitoring in CLI PHP scripts or long-running daemons.

Build Native Library

If you want to build the native library yourself:

./build.sh

This script detects your OS and compiles the appropriate C source code into the shared library.


License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published