PHPackages                             denismitr/mutex - 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. [Caching](/categories/caching)
4. /
5. denismitr/mutex

ActiveLibrary[Caching](/categories/caching)

denismitr/mutex
===============

PHP Mutex Library

v0.1(8y ago)38.5k↓50%[1 issues](https://github.com/denismitr/mutex/issues)MITPHPPHP &gt;=7.0.0

Since Nov 21Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (2)Used By (0)

PHP Mutex Library
=================

[](#php-mutex-library)

Author
------

[](#author)

[Denis Mitrofanov](https://thecollection.ru)

### Installation

[](#installation)

```
composer require denismitr/mutex
```

### Usage

[](#usage)

Initialization with factory:

- File lock

```
$lock = MutexFactory::fileLock(__FILE__); // or some other file name like /tmp/some-id
```

- Semaphore lock (linux only)

```
$lock = MutexFactory::semaphoreLock(__FILE__); // or some other file name like /tmp/some-id
```

- PRedis lock

```
$this->redis = new Client([
    'host' => 'localhost',
    'port' => 6379,
    'database' => 0,
]);

$this->lock = MutexFactory::pRedisLock($this->redis, "some-key", 20);
```

This far only these types of locks are supported

Using the lock instances

```
$lock->acquire();

// Do some critical stuff here

$lock->release();
```

With closures

```
$lock->safe(function() {
    // Lock will be acuqired and released automatically

    // Do some critical stuff safely
});
```

Performing a check first

```
$lock->try(function() use ($room, $from, $to) {
    // e.g
    return $room->isFree($from, $to);
})->then(function() use ($room, $from, $to) {
    // e.g.
    // Lock is aquired automatically

    $room->book($from, $to);
})->fail(function() use ($user) {
    // this callback will fire if the condition in try closure fails
    // e.g.
    $user->notify("Room is not available for requested time period.");
});
```

Looping in the safe, locked mode

```
$lock->loop($timeoutInSeconds, function($loop, $i) ($user, $ads) {
    // lock is acquired and released automatically when loop is done
    // e.g. send out only 10 ads to user friends

    // Laravel collections example
    $user->friends->each->notify($adds->random());

    if ($i >= 10) {
        $loop->stop();
    }
});
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3100d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d68ae5d5ca94f49a69f961a7825865d92247b09e276a25fcc6ad485d4c8c964?d=identicon)[denismitr](/maintainers/denismitr)

---

Top Contributors

[![denismitr](https://avatars.githubusercontent.com/u/16356446?v=4)](https://github.com/denismitr "denismitr (12 commits)")

---

Tags

mutexphpredissemaphoremutexpredisflocklock

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/denismitr-mutex/health.svg)

```
[![Health](https://phpackages.com/badges/denismitr-mutex/health.svg)](https://phpackages.com/packages/denismitr-mutex)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[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)[predis/predis-async

Asynchronous version of Predis

366348.4k](/packages/predis-predis-async)[predis/service-provider

Predis service provider for the Silex microframework

68546.6k1](/packages/predis-service-provider)[jamescauwelier/psredis

Sentinel client for the popular php redis client

77392.9k5](/packages/jamescauwelier-psredis)

PHPackages © 2026

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