File system watcher allowing for observeable handlers when a directory changes or content of the directory changes.
- PHP 5.4 >=
- Linux Files System / Mac OSX tested
- Windows (untested)
You used the file FileWatcher like you would use typical event listener. The main advantage to this class is it does not require installing any additional libraries and can simply be installed via composer and used immidiately. You can attach multiple listeners to the 3 main events:
- CREATE - File has been created
- MODIFIED - File has been changed (currently uses a md5 hash to identify change)
- DELETE - File has been deleted since last check
Attach to create events
use Stikman\FileWatcher;
$watcher = new FileWatcher("/tmp/mystuff");
$watcher->on(FileWatcher::CREATE, function() {
// do stuff
});
Set the pulling interval
$watcher = new FileWatcher("/tmp/mystuff");
$watcher->setInterval(100); // 100 millioseconds to check disk defaults to 25ms
Custom pattern match against file system for monitoring configuration data
$watcher = new FileWatcher("/tmp/mystuff", "*.json");
MIT