ralfhortt/php-watch-files

监控文件或文件夹,当内部内容发生变化时执行代码

1.0.0 2022-04-16 10:02 UTC

This package is auto-updated.

Last update: 2024-09-16 15:20:33 UTC


README

监控文件或文件夹,当内部内容发生变化时执行代码

演示

您可以运行以下命令来查看脚本如何工作

php index.php FILE_OR_FOLDER_PATH

基本用法

$watcher = new \ralfhortt\fswatcher\Watcher('FILE_OR_FOLDER_PATH_TO_WATCH', function ($event) {
    // Do whatever you want when file or folder is changed.
    if ($event->isAddition()){
        // File was added and file path will be $event->file
    } else if ($event->isModification()){
        // File was modified and file path will be $event->file
    }
});
$watcher->watch();

高级用法

$watcher = new \ralfhortt\fswatcher\Watcher('FILE_OR_FOLDER_PATH_TO_WATCH', 'callback', [
    'watchInterval' => 5,
    'cacheChanges' => true
]);

选项

致谢