ivopetkov/lock
Composer 安装命令:
composer require ivopetkov/lock
包简介
Locks library for PHP
README 文档
README
A simple locking library ... that is based on file locking (and that's awesome).
Why you need it
Imagine you have two tasks that you do not want to overlap (they modify the same data for example). Using this library will bring you peace of mind.
Keep in mind
The library uses file locking mechanism to ensure it works correctly. This means that it can be used only on applications/instances/processes that share a common file system. A website on one server does just that.
Install via Composer
composer require ivopetkov/lock
Usage
Using the following two methods (acquire() and release()) will ensure no two applications/instances/processes execute the code between them.
<?php require 'vendor/autoload.php'; use IvoPetkov\Lock; Lock::acquire('lock1'); // Acquires a lock and pauses other applications/instances/processes until the lock is released. // Do something awesome Lock::release('lock1'); // Releases the acquired lock.
Documentation
Full documentation is available as part of this repository.
Configuration
The default timeout to acquire a lock is 1.5 seconds. You can modify it by calling the following method:
Lock::setDefaultLockTimeout(2.5);
The temporary lock files needed by the library are stored in your OS temp dir. You can modify it by calling the following method:
Lock::setLocksDir('/some/other/temp/dir/');
If multiple applications use this library, you can call the following methods to prefix the keys provided. This way the different applications can use the same keys without interference.
Lock::setKeyPrefix('app1');
License
This project is licensed under the MIT License. See the license file for more information.
Contributing
Feel free to open new issues and contribute to the project. Let's make it awesome and let's do in a positive way.
Author
This library is created and maintained by Ivo Petkov (ivopetkov.com).
ivopetkov/lock 适用场景与选型建议
ivopetkov/lock 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.12k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ivopetkov/lock 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ivopetkov/lock 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 11
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-27