PHPackages                             lianran111/laravel-lock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lianran111/laravel-lock

ActiveLibrary

lianran111/laravel-lock
=======================

高性能, 分布式, 并发抢占锁, 队列锁

v1.0.8(4y ago)0310MITPHPPHP &gt;=7.2

Since Dec 28Pushed 4y agoCompare

[ Source](https://github.com/lianran111/laravel-lock)[ Packagist](https://packagist.org/packages/lianran111/laravel-lock)[ RSS](/packages/lianran111-laravel-lock/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (10)Used By (0)

环境要求
====

[](#环境要求)

```
1.PHP >= 7
2.composer
3.redis(必须支持lua)
4.predis

```

composer 安装
===========

[](#composer-安装)

移步 [composer中文网](https://www.phpcomposer.com/).

redis 安装
========

[](#redis-安装)

[redis中文网](http://www.redis.net.cn/)

predis 安装
=========

[](#predis-安装)

```
composer require predis/predis

```

lock 安装
=======

[](#lock-安装)

```
第一步, 安装alravel-lock
composer require lianran111/laravel-lock
第二步, 生成配置文件
php artisan vendor:publish --provider="Lock\LockServiceProvider"

```

抢占锁
===

[](#抢占锁)

lock(callable $callback, string $lock\_val)
-------------------------------------------

[](#lockcallable-callback-string-lock_val)

多进程并发时, 其中某一个进程得到锁后, 其他进程将被拒绝

```
$callback
            回调函数, 可返回值
$lock_val
            锁定值

```

多参数抢占锁
======

[](#多参数抢占锁)

lock(callable $callback, array $lock\_vals)
-------------------------------------------

[](#lockcallable-callback-array-lock_vals)

多进程并发时, 其中某一个进程得到锁后, 其他进程将被拒绝

```
$callback
            回调函数, 可返回值
$lock_vals
            锁定值(数组)

```

队列锁
===

[](#队列锁)

queueLock($closure, $lock\_val, $max\_queue\_process = 100)
-----------------------------------------------------------

[](#queuelockclosure-lock_val-max_queue_process--100)

多进程并发时, 其中某一个进程得到锁后, 其他进程将等待解锁(配置最大等待进程后, 超过等待数量后进程将被拒绝)

```
$callback
                回调函数, 可返回值
$lock_val
                锁定值
$max_queue_process
                队列最大等待进程

```

多参数队列锁
======

[](#多参数队列锁)

queueLock($closure, $lock\_vals, $max\_queue\_process = 100)
------------------------------------------------------------

[](#queuelockclosure-lock_vals-max_queue_process--100)

多进程并发时, 其中某一个进程得到锁后, 其他进程将等待解锁(配置最大等待进程后, 超过等待数量后进程将被拒绝)

```
$callback
                回调函数, 可返回值
$lock_vals
                锁定值(数组)
$max_queue_process
                队列最大等待进程

```

使用
==

[](#使用)

```
//静态调用
$lock_val = 'user:pay:1';
Lock::lock(function($redis){
   echo 'hello world!';
}, $lock_val);

//实例化调用
$lock = new Lock();
$lock_val = 'user:pay:1';
$lock->lock(function($redis){
    echo 'hello world!';
}, $lock_val);

//多参数锁
$lock = new Lock();
$lock_val[] = 'user:pay:1';
$lock_val[] = 'user:pay:2';
$lock->lock(function($redis){
    echo 'hello world!';
}, $lock_val);

```

限流
==

[](#限流)

isActionAllowed($key, $period, $max\_count)
-------------------------------------------

[](#isactionallowedkey-period-max_count)

```
$key        限制key
$period     限制时间(秒)
$max_count  限制时间内最大数量

```

config配置
========

[](#config配置)

```
 /*
    |--------------------------------------------------------------------------
    | lock配置文件
    |--------------------------------------------------------------------------
    |
    |drive 锁驱动(默认redis)
    |
    |redis redis驱动配置
    |   host 地址
    |   port 端口
    |
    |params 参数配置
    |   max_queue_process  进程池最大进程
    |   expiration         锁值过期时间
    |
    */
'drive' =>  'redis',

'redis' =>  [
    'host'                  =>  '127.0.0.1',
    'port'                  =>  6379,
    'read_write_timeout'    =>  0,
    'persistent'            =>  true,
],

'params' => [
    'max_queue_process' =>  100,
    'expiration'        =>  5
]

```

laravel-lock
============

[](#laravel-lock)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 89.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~115 days

Recently: every ~191 days

Total

9

Last Release

1770d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.0

v1.0.8PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5bdf010ed5bd5bf69657a98da3a84cadd9ce882fe45a6642d09ee10cfeeb1c50?d=identicon)[xbm](/maintainers/xbm)

---

Top Contributors

[![zhaocong6](https://avatars.githubusercontent.com/u/26103783?v=4)](https://github.com/zhaocong6 "zhaocong6 (26 commits)")[![lianran111](https://avatars.githubusercontent.com/u/33922757?v=4)](https://github.com/lianran111 "lianran111 (3 commits)")

---

Tags

lock

### Embed Badge

![Health badge](/badges/lianran111-laravel-lock/health.svg)

```
[![Health](https://phpackages.com/badges/lianran111-laravel-lock/health.svg)](https://phpackages.com/packages/lianran111-laravel-lock)
```

###  Alternatives

[malkusch/lock

Mutex library for exclusive code execution.

9459.6M27](/packages/malkusch-lock)[arvenil/ninja-mutex

Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking

1873.7M27](/packages/arvenil-ninja-mutex)[nabao/lock

高性能, 分布式, 并发抢占锁, 队列锁

2821.4k](/packages/nabao-lock)[sheadawson/silverstripe-editlock

Prevents a CMS user from editing a record that another CMS user is currently editing

25113.0k](/packages/sheadawson-silverstripe-editlock)[yii-dream-team/yii2-lockable-activerecord

Pessimistic locking behavior for Yii2 ActiveRecord

1886.5k](/packages/yii-dream-team-yii2-lockable-activerecord)[joshdifabio/resource-pool

Regulate the concurrency level of your async components

3321.1k1](/packages/joshdifabio-resource-pool)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
