acet/reslock
Composer 安装命令:
composer require acet/reslock
包简介
Dependable advisory resource lock - for files and other contentious resources
README 文档
README
Advisory resource lock for files and other resources (similar to flock but works on all platforms).
Mainly used to protect a file from being written-to by two or more processes at the same time. This is similar to the PHP flock() function, the differences being that this is dependable (even on Windows) and that the lock applies to any resource - not just files.
It works by checking for the absence/presence of a directory to determine whether an exclusive lock has been achieved. A directory is used in preference to a file because the mkdir() function will, in a single platform-independent operation, return whether or not a directory exists and create it if it doesn't.
On Windows systems, at least, this method is more reliable than standard flock() which requires two operating system operations - check whether the lock-file exists, and create it if it doesn't. Since there are 2 operations, it is possible for several processes to be checking at the same time; each one concluding that the lock-file doesn't exist, each one creating the file, and each one believing it has an exclusive lock.
####Requirements ResLock requires the following:
- PHP 5.3.3+
####Installation ResLock is installed via Composer. To add a dependency to ResLock in your project, either
Run the following to use the latest stable version
composer require acet/reslock
or if you want the latest master version
composer require acet/reslock:dev-master
You can also manually edit your composer.json file
{ "require": { "acet/reslock": "v0.1.*" } }
####Example - Update a file which may have other interested parties
use acet\ResLock;
$contentious_file = 'contentious.file';
$reslock = new ResLock();
// Provide a name for the resource (any string will do - can be a file name, or the name of your cat)
if ($reslock->lock('tiddles')) {
// resource successfully locked
$file_contents = file_get_contents($contentious_file);
$string = "Do something";
file_put_contents($contentious_file, $string);
$reslock->unlock();
}
else {
throw new exception("Unable to lock the resource");
}
acet/reslock 适用场景与选型建议
acet/reslock 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「lock」 「flock」 「file lock」 「race condition」 「advisory lock」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 acet/reslock 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 acet/reslock 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 acet/reslock 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Redis distributed locks for laravel
Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking
A Symfony bundle for Mutex implementation for PHP
Simple php library providing OOP-interface to file locks.
Symfony Lock Component
Symfony lock Tarantool store
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2020-06-10