PHPackages                             kcyeu/php-redlock - 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. kcyeu/php-redlock

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

kcyeu/php-redlock
=================

Redis distributed locks in PHP

014PHP

Since Mar 26Pushed 11y ago1 watchersCompare

[ Source](https://github.com/kcyeu/php-redlock)[ Packagist](https://packagist.org/packages/kcyeu/php-redlock)[ RSS](/packages/kcyeu-php-redlock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

PHP-Redlock
===========

[](#php-redlock)

> Redis distributed locks in PHP

Based on [Redlock-rb](https://github.com/antirez/redlock-rb) by [Salvatore Sanfilippo](https://github.com/antirez) and [Redlock-php](https://github.com/ronnylt/redlock-php) by [Ronny López](https://github.com/ronnylt). This library implements the Redis-based distributed lock manager algorithm [described in this blog post](http://antirez.com/news/77).

Support cluster mode using [phpredis](https://github.com/phpredis/phpredis/tree/feature/redis_cluster_autofailover) PECL extention.

To create a lock manager:

```
$servers = array(
    array('127.0.0.1', 6379),
    array('127.0.0.1', 6380),
    array('127.0.0.1', 6381),
);

$redLock = new RedLock($servers);
```

To acquire a lock:

```
$lock = $redLock->lock('my_resource_name', 1000);
```

Where the resource name is an unique identifier of what you are trying to lock and 1000 is the number of milliseconds for the validity time.

The returned value is `false` if the lock was not acquired (you may try again), otherwise an array representing the lock is returned, having three keys:

```
Array
(
    [validity] => 9897.3020019531
    [resource] => my_resource_name
    [token] => 53771bfa1e775
)
```

- validity, an integer representing the number of milliseconds the lock will be valid.
- resource, the name of the locked resource as specified by the user.
- token, a random token value which is used to safe reclaim the lock.

To release a lock:

```
    $redLock->unlock($lock)
```

It is possible to setup the number of retries (by default 3) and the retry delay (by default 200 milliseconds) used to acquire the lock.

The retry delay is actually chosen at random between `$retryDelay / 2` milliseconds and the specified `$retryDelay` value.

**Disclaimer**: As stated in the original antirez's version, this code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

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

---

Top Contributors

[![ronnylt](https://avatars.githubusercontent.com/u/24546?v=4)](https://github.com/ronnylt "ronnylt (3 commits)")[![kcyeu](https://avatars.githubusercontent.com/u/7254000?v=4)](https://github.com/kcyeu "kcyeu (2 commits)")[![joni2back](https://avatars.githubusercontent.com/u/2049935?v=4)](https://github.com/joni2back "joni2back (1 commits)")[![sp-ronny-lopez](https://avatars.githubusercontent.com/u/6653187?v=4)](https://github.com/sp-ronny-lopez "sp-ronny-lopez (1 commits)")[![zeroasterisk](https://avatars.githubusercontent.com/u/23422?v=4)](https://github.com/zeroasterisk "zeroasterisk (1 commits)")

### Embed Badge

![Health badge](/badges/kcyeu-php-redlock/health.svg)

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

PHPackages © 2026

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