reportico/fresh-file
Composer 安装命令:
composer require reportico/fresh-file
包简介
Simple, fast, standalone PHP lib, that helps You to define, if any of your files were modified since last time You check - Is this file FRESH?
README 文档
README
Simple, fast, standalone PHP library, that helps You to define, if any of your files were modified since last time You check - Is this file FRESH?
Script uses filemtime() function (with optional clearstatcache()) to get last modification time of file. All modification times are stored in one cache file (if You use multiple instances, multiple files will be created), so even when you use this library for houndreds of files, it will store their times in one file, and read&write of cache file will be done one time per request.
Usage
You can create many instances as You want, or create one, and use it as dummy-singleton accessed by static method of class. As argument You must pass a valid cache filepath, where script can place it's metadata cache.
// Create by object $ff = new FreshFile($cacheFilepath); // Create using factory $ff = FreshFile::create($cacheFilepath);
Once created You can use Your object anywhere You pass it, or get the existend object from static call.
// Get existent object from class $ff = FreshFile::get();
In first solution You must pass this object anywhere You want use it. In second solution You have to create object one time, and You can use it anywhere You want without passing it as argument.
Prevent save cache on object destroy
FreshFile saves metadata file when FreshFile object destroy (when PHP script/request ends), by default. But in some cases You may need to prevent this. Maybe there was some error in Your code and You won't save the current collected data in cache? To do this, pass the second argument as false to prevent this. From now, You must manually close the FreshFile and save the metadata collected in the request by using close() method.
// Prevent default save on destroy object $ff = new FreshFile($cacheFilepath, false); $ff = FreshFile::create($cacheFilepath, false); // ...some code... // At the end, close the FreshFile and save metadata $ff->close();
Remember!
If You have prevented save on destroy, You must always close the FreshFile object after Your script ends!
Use case
You can check one or many files at one time. If You pass array of filepaths, and any of files will not be fresh (even 1 from 100), method returns true - which means file is fresh and some operations with this file need to be done.
// One file if($ff->isFresh($file)) // Do something... // Many files if($ff->isFresh([ $file1, $file2, $file3 ])) // Do something...
If You check if the file is fresh, script automatically updates metadata for this file, and next time You ask object if the same file is fresh, script returns false - that means this file do not need to be updated. Even when you call again line by line in the same script/request!!
var_dump($ff->isFresh($file)); // returns true var_dump($ff->isFresh($file)); // returns false !!! var_dump($ff->isFresh($file)); // returns false !!!
Related files
You can define related files of one main file. This is usefull when You compile LESS or SCSS files with imports, create imports in configuration files, etc. Once passed related files, script will check also if these related files are fresh. If main file or any of related files will change, You will be noticed.
$ff->setRelatedFiles($file, $relatedFiles); $ff->isFresh($file);
You can also set related files, after first fresh-check. This can be usefull when You detect, if any of these files was modified, and You want to update related files for this file.
if($ff->isFresh($file)) { // Do something with Config, LESS, SCSS... // After compiling files in library, You can get imported files from library, and set // them into FreshFile object. Next time these files will also be checked if were modified. // FreshFile remember related files between requests. $relatedFiles = $object->getImportedFiles(); $ff->setRelatedFiles($file, $relatedFiles); }
Licence
This code is licensed under MIT License.
reportico/fresh-file 适用场景与选型建议
reportico/fresh-file 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.6k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「file-system」 「filemanager」 「cache-control」 「file-manager」 「fresh」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 reportico/fresh-file 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reportico/fresh-file 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 reportico/fresh-file 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony2 Bundle for serving protected files.
A SDK for working with B2 cloud storage.
Type-safe functions for file system operations with proper exception handling
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
A lightweight file-system cache system
统计信息
- 总下载量: 10.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-07