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.1(1mo ago)32.0M↓58.7%16MITPHPPHP ^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 2w ago

READMEChangelog (5)Dependencies (12)Versions (8)Used By (6)

[   ![](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

48

—

FairBetter than 94% of packages

Maintenance52

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity59

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 ~197 days

Recently: every ~271 days

Total

7

Last Release

39d 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

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.6k79.3k91](/packages/pocketmine-pocketmine-mp)[markocupic/calendar-event-booking-bundle

Contao Calendar Event Booking Bundle

125.3k1](/packages/markocupic-calendar-event-booking-bundle)[mynaparrot/plugnmeet-sdk

plugNmeet PHP SDK

113.1k](/packages/mynaparrot-plugnmeet-sdk)

PHPackages © 2026

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