Skip to content

File system watcher allowing for observeable handlers when a directory changes or a file is modified

License

Notifications You must be signed in to change notification settings

stikmanw/Watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Watcher Build Status

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

About

File system watcher allowing for observeable handlers when a directory changes or a file is modified

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages