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

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

swordev/mutex
=============

Read-write concurrency control

0.1.0(5y ago)13MITPHP

Since Jul 27Pushed 5y agoCompare

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

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Mutex
=====

[](#mutex)

> Read-write concurrency control

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

[](#installation)

```
composer require @swordev/mutex
```

Usage
-----

[](#usage)

### File read/write lock

[](#file-readwrite-lock)

```
use Swordev\Mutex\FileMutex;

$mutex1 = new FileMutex('key');
$mutex2 = new FileMutex('key');

$mutex1->readLock(); // true
$mutex2->writeLock(); // false

$mutex1->unlock(); // true
$mutex2->writeLock(); // true
```

### Timeout

[](#timeout)

```
use Swordev\Mutex\FileMutex;

$mutex = new FileMutex('key');
$mutex->writeLock(5000);
```

### Contextual lock

[](#contextual-lock)

```
use Swordev\Mutex\FileMutex;

class Foo {
	function method() {
		$mutex = new FileMutex(__CLASS__ . '|' . __FUNCTION__);
		$mutex->writeLock();
		// ...
	}
}
```

### Mutex factory

[](#mutex-factory)

```
use Swordev\Mutex\MutexFactory;

$mutex = new MutexFactory::create(FileMutex::class, 'key');
```

Development
-----------

[](#development)

### Test

[](#test)

```
composer run test
```

### Analyse

[](#analyse)

```
composer run analyse
```

Author
------

[](#author)

Juanra GM -

Distributed under the MIT license.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

2121d ago

### Community

Maintainers

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

---

Top Contributors

[![juanrgm](https://avatars.githubusercontent.com/u/54169354?v=4)](https://github.com/juanrgm "juanrgm (3 commits)")

---

Tags

concurrencysemaphoremutexflocklock

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/lock

Creates and manages locks, a mechanism to provide exclusive access to a shared resource

514127.6M459](/packages/symfony-lock)[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)[zerkalica/semaphore

This library provides an api for semaphore acquire and release

1119.0k1](/packages/zerkalica-semaphore)[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)
