定制 friendsofhyperf/lock 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

friendsofhyperf/lock

最新稳定版本:v3.2.0-beta.1

Composer 安装命令:

composer require friendsofhyperf/lock

包简介

The lock component for Hyperf.

关键字:

README 文档

README

Latest Stable Version Total Downloads License

The lock component for Hyperf. 中文说明

Installation

  • Require
composer require friendsofhyperf/lock
  • Publish
php bin/hyperf.php vendor:publish friendsofhyperf/lock -i config

Usage

You may create and manage locks using the lock() method:

$lock = lock($name = 'foo', $seconds = 10, $owner = null); if ($lock->get()) { // Lock acquired for 10 seconds... $lock->release(); }

The get method also accepts a closure. After the closure is executed, Will automatically release the lock:

lock('foo')->get(function () { // Lock acquired indefinitely and automatically released... });

If the lock is not available at the moment you request it, you may instruct the lock to wait for a specified number of seconds. If the lock can not be acquired within the specified time limit, an FriendsOfHyperf\Lock\Exception\LockTimeoutException will be thrown:

use FriendsOfHyperf\Lock\Exception\LockTimeoutException; $lock = lock('foo', 10); try { $lock->block(5); // Lock acquired after waiting maximum of 5 seconds... } catch (LockTimeoutException $e) { // Unable to acquire lock... } finally { $lock->release(); } lock('foo', 10)->block(5, function () { // Lock acquired after waiting maximum of 5 seconds... });

Using by annotation

use FriendsOfHyperf\Lock\Annotation\Lock; use FriendsOfHyperf\Lock\Driver\LockInterface; class Foo { #[Lock(name:"foo", seconds:10)] protected LockInterface $lock; public function bar() { $this->lock->get(function () { // Lock acquired indefinitely and automatically released... }); } }

Contact

License

MIT

统计信息

  • 总下载量: 44.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固