承接 vox/file-watcher 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vox/file-watcher

Composer 安装命令:

composer require vox/file-watcher

包简介

README 文档

README

Installing

this library requires PHP 7.1+ and pecl inotify extension inotify

$ sudo pecl install inotify
$ composer require vox/file-watcher

Usage

Usage is simple, first configure the context:

use Vox\FileWatcher\FolderWatcherContext;
use Vox\FileWatcher\FolderWatcher;

$context = new FolderWatcherContext();
$context->blocking = true;  //if set to false, php will not block when readEvents is called, async code can be done
$context->recursive = true; //if set to true subfolders will be also watched, 
                            //and so new subfolders will be automatically be watched

Then obtain the watcher instance:

$watcher = new FolderWatcher('/folder/to/watch', $context);

Now, all you need is the callback actions for each possible event, like this:

$watcher->onCreated(function (FileWatcherEvent $event, FolderWatcherContext $context) {
    //do something when a file is created
});

there are other events to be listened:

  • onMoved
  • onOpened
  • onModified
  • onClosed
  • onDeleted

Finaly call the dispatch event method to listen to filesystem changes:

$watcher->dispatchEvents();

Note that, this operation will block untill an event occurs, and returns imediately as soon an filesystem event on the watched folder happens. This block can be avoided setting the context blocking property to false, that way, if no event ocurred between the watcher instancing and the call of this method an empty array will be returned

The readEvents method

You may notice that the FolderWatcher class has a readEvents method, this method can be called in case you may need to get the events without dispatching the events. this method returns an array of Vox\FileWatcher\FileWatcherEvent, this class has various methods to help identify what is this event about:

  • isDir
  • isWatchedDir - returns true if this event refers to a dir wihch is currently beig watched
  • isMovedFile
  • isMovedFrom
  • isMovedTo
  • isCreated
  • isModified
  • isDeleted
  • isOpened
  • isClosed
  • getOriginPath - if its a moved file, get the former path as SplFileInfo instance
  • getPath - the file path as SplFileInfo instance
  • getCookie - if the event has a cookie, than its a moved file, the cookie is what binds the moved from and moved to events

Note: not all the movedTo files has a origin path, only those that are moved between watched dirs, when a file comes from a directory wihch is not being watched it will have no moved from event, therefore no originPath

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固