takuya/php-fsnotifywait-wrapper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

takuya/php-fsnotifywait-wrapper

最新稳定版本:0.2.1

Composer 安装命令:

composer require takuya/php-fsnotifywait-wrapper

包简介

fsnotifywait of fanotify command wrapper

README 文档

README

Utilize fsnotifywait command.

<?php
$fsnotify = new FsNotifyWrap('/etc');
$fsnotify->addObserver($observer = new FsEventObserver());
$observer->watch(function(FanEvent $ev ){
  $this->queue->push($ev->getEventSource());
});
$fsnotify->listen();

Watch delete event

$fsnotify = new FsNotifyWrap('/etc');
$fsnotify->addObserver($observer = new FsEventObserver());
$observer->addEventListener(
   FsNotifyDelete:class,
  fn($ev)=>dump($ev->getEventSource());
);
$fsnotify->listen();

EventSource is a simple object like This.

{#372
  +"time": "2025-04-04 23:50:31"
  +"type": "CREATE"
  +"file": "/tmp/php-tmpdir-gUEKhP8s/sample.txt"
}

installation

composer require takuya/php-fsnotifywait-wrapper

command

Watch command included.

sudo vendor/bin/fswatch -S --dir /home --exec /usr/bin/echo 

If something changed, exec echo.sh

about fsnotifywait

fsnotifywait can be added as Linux Command. run apt install inotofy-tools.

This command can watch file changed by fanotify API. fanotify is added Linux Kernel 5.10.

Compare inotifywatch, fsnotifywait uses FAN( fanotify API not inotify).

fanotify API can watch arbitrarily chosen dir, and recursively too many file in it which inotify cannot watch.

fsnotifywait -q --format '#%w%f %e ::::' -m -r -S -e create,delete,move,modify /mnt/sample
fsnotifywait -q --timefmt '%F %T' --format '{"time":"%T","type":"%e"}:%w%f%0' -m -r -F -e create,delete,move,modify,moved_from,moved_to /opt/work/sample/

This command will output this.

{"time":"2025-04-02 03:55:29","type":"CREATE"}:/opt/work/sample/aTooc8Eeph.txt
{"time":"2025-04-02 03:55:29","type":"MODIFY"}:/opt/work/sample/aTooc8Eeph.txt
{"time":"2025-04-02 03:55:29","type":"CREATE"}:/opt/work/sample/oFam1Aivoh.txt
{"time":"2025-04-02 03:55:29","type":"MODIFY"}:/opt/work/sample/oFam1Aivoh.txt
{"time":"2025-04-02 03:55:29","type":"CREATE"}:/opt/work/sample/jumaiPuSh2.txt
{"time":"2025-04-02 03:57:42","type":"CREATE,ISDIR"}:/opt/work/sample/sub

see

  • man fanotify
  • man fsnotifywatch
  • man fsnotifywait

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-04-04