PHPackages                             roadrunner-php/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. roadrunner-php/lock

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

roadrunner-php/lock
===================

This package provides a PHP integration package for the RoadRunner Lock plugin, which allows for easy management of distributed locks in PHP applications. The plugin provides a fast, lightweight, and reliable way to acquire, release, and manage locks in a distributed environment, making it ideal for use in high-traffic web applications and microservices.

1.0.0(2y ago)31.6M↓33.6%15MITPHPPHP ^8.1

Since Apr 13Pushed 2y ago3 watchersCompare

[ Source](https://github.com/roadrunner-php/lock)[ Packagist](https://packagist.org/packages/roadrunner-php/lock)[ Docs](https://roadrunner.dev/)[ GitHub Sponsors](https://github.com/sponsors/roadrunner-server)[ RSS](/packages/roadrunner-php-lock/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (7)Used By (5)

[   ![](https://github.com/roadrunner-server/.github/assets/8040338/040fb694-1dd3-4865-9d29-8e0748c2c8b8) ](https://roadrunner.dev)RoadRunner locks
================

[](#roadrunner-locks)

[![PHP Version Require](https://camo.githubusercontent.com/468229444c423d1a80199309f1461c42cc3e510027e0394f2c578ce9a0dfd435/68747470733a2f2f706f7365722e707567782e6f72672f726f616472756e6e65722d7068702f6c6f636b2f726571756972652f706870)](https://packagist.org/packages/roadrunner-php/lock)[![Latest Stable Version](https://camo.githubusercontent.com/5a9c79261ec335f36f9fde7b6c9665bedf03637d5c89ec62a370781a2cc3c0ce/68747470733a2f2f706f7365722e707567782e6f72672f726f616472756e6e65722d7068702f6c6f636b2f762f737461626c65)](https://packagist.org/packages/roadrunner-php/lock)[![phpunit](https://github.com/roadrunner-php/lock/actions/workflows/phpunit.yml/badge.svg)](https://github.com/roadrunner-php/lock/actions)[![psalm](https://github.com/roadrunner-php/lock/actions/workflows/psalm.yml/badge.svg)](https://github.com/roadrunner-php/lock/actions)[![Codecov](https://camo.githubusercontent.com/c256e25d22f16673facaa3d730191126e2ba1fa594dbe30cac9ee3dc41482c12/68747470733a2f2f636f6465636f762e696f2f67682f726f616472756e6e65722d7068702f6c6f636b2f6272616e63682f312e782f67726170682f62616467652e737667)](https://codecov.io/gh/roadrunner-php/lock/)[![Total Downloads](https://camo.githubusercontent.com/6f2e6ae6b47ee608acf18026e48bc5c4037dbd6cab86dcc50b6c3889ff4c1047/68747470733a2f2f706f7365722e707567782e6f72672f726f616472756e6e65722d7068702f6c6f636b2f646f776e6c6f616473)](https://packagist.org/packages/roadrunner-php/lock)[![](https://camo.githubusercontent.com/4442b73a11753b80fdd7b442ddbfaf8383902c8b9ffa66ed1718e8c62e102f2e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973636f72642d636861742d6d6167656e74612e737667)](https://discord.gg/spiralphp)

This package provides a PHP integration package for the RoadRunner Lock plugin, which allows for easy management of distributed locks in PHP applications. The plugin provides a fast, lightweight, and reliable way to acquire, release, and manage locks in a distributed environment, making it ideal for use in high-traffic web applications and microservices.

Requirements
------------

[](#requirements)

Make sure that your server is configured with following PHP version and extensions:

- PHP 8.1+

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require roadrunner-php/lock
```

Usage
-----

[](#usage)

```
use RoadRunner\Lock\Lock;
use Spiral\Goridge\RPC\RPC;

require __DIR__ . '/vendor/autoload.php';

$lock = new Lock(RPC::create('tcp://127.0.0.1:6001'));
```

### Acquire lock

[](#acquire-lock)

Locks a resource so that it can be accessed by one process at a time. When a resource is locked, other processes that attempt to lock the same resource will be blocked until the lock is released.

```
$id = $lock->lock('pdf:create');

// Acquire lock with ttl - 10 seconds
$id = $lock->lock('pdf:create', ttl: 10);
// or
$id = $lock->lock('pdf:create', ttl: new \DateInterval('PT10S'));

// Acquire lock and wait 5 seconds until lock will be released
$id = $lock->lock('pdf:create', wait: 5);
// or
$id = $lock->lock('pdf:create', wait: new \DateInterval('PT5S'));

// Acquire lock with id - 14e1b600-9e97-11d8-9f32-f2801f1b9fd1
$id = $lock->lock('pdf:create', id: '14e1b600-9e97-11d8-9f32-f2801f1b9fd1');
```

### Acquire read lock

[](#acquire-read-lock)

Locks a resource for shared access, allowing multiple processes to access the resource simultaneously. When a resource is locked for shared access, other processes that attempt to lock the resource for exclusive access will be blocked until all shared locks are released.

```
$id = $lock->lockRead('pdf:create', ttl: 10);
// or
$id = $lock->lockRead('pdf:create', ttl: new \DateInterval('PT10S'));

// Acquire lock and wait 5 seconds until lock will be released
$id = $lock->lockRead('pdf:create', wait: 5);
// or
$id = $lock->lockRead('pdf:create', wait: new \DateInterval('PT5S'));

// Acquire lock with id - 14e1b600-9e97-11d8-9f32-f2801f1b9fd1
$id = $lock->lockRead('pdf:create', id: '14e1b600-9e97-11d8-9f32-f2801f1b9fd1');
```

### Release lock

[](#release-lock)

Releases an exclusive lock or read lock on a resource that was previously acquired by a call to `lock()`or `lockRead()`.

```
// Release lock after task is done.
$lock->release('pdf:create', $id);

// Force release lock
$lock->forceRelease('pdf:create');
```

### Check lock

[](#check-lock)

Checks if a resource is currently locked and returns information about the lock.

```
$status = $lock->exists('pdf:create');
if($status) {
    // Lock exists
} else {
    // Lock not exists
}
```

### Update TTL

[](#update-ttl)

Updates the time-to-live (TTL) for the locked resource.

```
// Add 10 seconds to lock ttl
$lock->updateTTL('pdf:create', $id, 10);
// or
$lock->updateTTL('pdf:create', $id, new \DateInterval('PT10S'));
```

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [butschster](https://github.com/butschster)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.3% 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 ~60 days

Recently: every ~53 days

Total

6

Last Release

828d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/796136?v=4)[Anton Tsitou](/maintainers/wolfy-j)[@wolfy-j](https://github.com/wolfy-j)

![](https://avatars.githubusercontent.com/u/773481?v=4)[Pavel Buchnev](/maintainers/butschster)[@butschster](https://github.com/butschster)

---

Top Contributors

[![msmakouz](https://avatars.githubusercontent.com/u/67324318?v=4)](https://github.com/msmakouz "msmakouz (9 commits)")[![butschster](https://avatars.githubusercontent.com/u/773481?v=4)](https://github.com/butschster "butschster (3 commits)")[![gam6itko](https://avatars.githubusercontent.com/u/3841197?v=4)](https://github.com/gam6itko "gam6itko (2 commits)")[![rustatian](https://avatars.githubusercontent.com/u/8040338?v=4)](https://github.com/rustatian "rustatian (2 commits)")

---

Tags

locksmutexmutex-lockphproadrunnerlockspiralroadrunner-php

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[zerkalica/semaphore

This library provides an api for semaphore acquire and release

1119.0k1](/packages/zerkalica-semaphore)[nabao/laravel-lock

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

271.5k](/packages/nabao-laravel-lock)[pudongping/hyperf-wise-locksmith

A mutex library provider for the Hyperf framework, designed to enable serialized execution of PHP code in high-concurrency scenarios.

106.3k2](/packages/pudongping-hyperf-wise-locksmith)

PHPackages © 2026

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