PHP.7 file watcher
using composer: composer require laudeon/fileon
use Fileon\Resource;
use Fileon\Watcher;
$resource = new Resource(_DIR_);
$watcher = new Watcher($resource);
$watcher->onNew(function(\SplFileInfo $file){
//...
});
$watcher->onModified(function(\SplFileInfo $file){
//...
});
$watcher->watch(function() use ($watcher) {
if(...) {
$watcher->stop();
}
});
$resource
is an instance of Fileon\Resource.$sleep
, optional, is the sleep time on each loop turn of the watcher, in microseconds. Defautl is 1000000
$callback
must be a callable argument (function). It will be executed at the end of each loop turn.
Stop the watcher.
Return the status of the watcher.