stikmanw/file-event-watcher

File system watcher allowing for observeable handlers when a directory changes or content of the directory changes.

Installs: 217

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Type:libarary

v0.1.0 2015-06-24 03:05 UTC

This package is not auto-updated.

Last update: 2024-04-13 15:44:47 UTC


README

File system watcher allowing for observeable handlers when a directory changes or content of the directory changes.

Requirements

  • PHP 5.4 >=
  • Linux Files System / Mac OSX tested
  • Windows (untested)

Description

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

Example

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"); 

License

MIT