PHPackages                             php-comp/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-comp/lock

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

php-comp/lock
=============

lock library of the php

v1.1.0(7y ago)57012MITPHPPHP &gt;7.0.0

Since Mar 2Pushed 7y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (2)

php 共享锁的实现
==========

[](#php-共享锁的实现)

[![License](https://camo.githubusercontent.com/e72bce6c1bd1391552a8679d835cd328d43dc47d30ebb8e03ef82d12086737e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068702d636f6d702f6c6f636b2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Php Version](https://camo.githubusercontent.com/5127919eba34cfd4efa2e1d76a62f25de4061ec0a31a434fd9b23f6b16fc2c0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e302d627269676874677265656e2e7376673f6d61784167653d32353932303030)](https://packagist.org/packages/php-comp/lock)[![Latest Stable Version](https://camo.githubusercontent.com/e75e676fa9bae22ce9ccdfe8f7144d6bc063ebd112e276de8886acd27072a188/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d636f6d702f6c6f636b2e737667)](https://packagist.org/packages/php-comp/lock)

- `DatabaseLock` 数据库方式的共享锁
- `FileLock` 文件加锁的方式实现
- `SemaphoreLock` 基于信号量（是系统提供的一种原子操作）的方式实现。需php编译时 `--enable-sysvsem`
- `MemcacheLock` 基于memcache实现

> 参考：

安装
--

[](#安装)

- composer

```
{
    "require": {
        "php-comp/lock": "dev-master"
    }
}
```

- 直接拉取

```
git clone https://git.oschina.net/inhere/php-lock.git // git@osc
git clone https://github.com/inhere/php-lock.git // github
```

使用
--

[](#使用)

```
use PhpComp\Lock\Lock;

$locker = new Lock([
    'driver' => '', // allow: File Database Memcache Semaphore
    'tmpDir' => '/tmp', // tmp path, if use FileLock
]);

$key = 'op1';

if ($locker->lock($key)) {
    // do something ...

    $locker->unlock($key);
}
```

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~132 days

Total

3

Last Release

2731d ago

PHP version history (2 changes)v1.0.1PHP &gt;=7.0.0

v1.1.0PHP &gt;7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d23e1decaf354e8f36a7ad61128865dc78dd63336c2d023d79aa3ff8ba2a05ff?d=identicon)[inhere](/maintainers/inhere)

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (13 commits)")

---

Tags

file-locklockphp-libraryphp-lockshare-lockphplibrarylockfile lockphp-lockdb-locksysvsem-lock

### Embed Badge

![Health badge](/badges/php-comp-lock/health.svg)

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

PHPackages © 2026

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