inwebo/dirtree-by-file-content-hash
Composer 安装命令:
composer require inwebo/dirtree-by-file-content-hash
包简介
How can one store a large number of files while maintaining a high level of performance during access? One solution is file content hashing.
README 文档
README
How can one store a large number of files while maintaining a high level of performance during access? One solution is file content hashing.
This class will generate SHA 512 hash from the content of a file, and it will return you a directory structure based on the file hash.
How to
<?php include './vendor/autoload.php'; use Inwebo\DirTree\FromSplFileObject; try { // Its content is null, its hash is cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e $dirTree = (new FromSplFileObject(new SplFileObject('./tests/empty-file.txt'))); var_dump($dirTree->toArray()); // array(2) { // [0] => // string(2) "cf" // [1] => // string(2) "83" //} var_dump($dirTree->toArray(true)); // array(3) { // [0] => // string(2) "cf" // [1] => // string(2) "83" // [2] => // string(10) "empty-file.txt" // } var_dump($dirTree->toString()); // string (5) cf/83 var_dump($dirTree->toString(true)); // string(20) "cf/83/empty-file.txt" $dirTree->setDirTreeDepth(6); var_dump($dirTree->toArray()); // array(6) { // [0] => // string(2) "cf" // [1] => // string(2) "83" // [2] => // string(2) "e1" // [3] => // string(2) "35" // [4] => // string(2) "7e" // [5] => // string(2) "ef" //} $dirTree->setDirTreeDepth(6); $dirTree->setDirNameLength(6); var_dump($dirTree->toArray()); // array(6) { // [0] => // string(6) "cf83e1" // [1] => // string(6) "357eef" // [2] => // string(6) "b8bdf1" // [3] => // string(6) "542850" // [4] => // string(6) "d66d80" // [5] => // string(6) "07d620" //} var_dump($dirTree->toString(true)); // string(56) "cf83e1/357eef/b8bdf1/542850/d66d80/07d620/empty-file.txt" // Invalid strategy, because 128 - 2 * 128 = -128 is not equal or superior to 0 $dirTree->setDirNameLength(2); $dirTree->setDirTreeDepth(128); // Throw an RuntimeException $dirTree->toArray(); } catch (\Exception $e) { // Do something }
Install
composer req inwebo/dirtree-by-file-content-hash
Web
inwebo/dirtree-by-file-content-hash 适用场景与选型建议
inwebo/dirtree-by-file-content-hash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 inwebo/dirtree-by-file-content-hash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inwebo/dirtree-by-file-content-hash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2023-10-09