PHPackages                             phlib/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. phlib/mutex

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

phlib/mutex
===========

PHP mutex handling in different ways

3.0.2(4mo ago)16.9kLGPL-3.0PHPPHP ^7.4 || ^8.0CI passing

Since Jun 23Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/phlib/mutex)[ Packagist](https://packagist.org/packages/phlib/mutex)[ Docs](https://github.com/phlib/mutex)[ RSS](/packages/phlib-mutex/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (4)Versions (7)Used By (0)

phlib/mutex
===========

[](#phlibmutex)

[![Code Checks](https://camo.githubusercontent.com/add5506134dc966628f12811038a4d992a965b7af3e121ec6cfb8c09591b6b08/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f6d757465782f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/mutex/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/98dc29a434816727fea33365816a7d0ebcf950797d3a67bba1b0c37d37f52fbd/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f6d757465782e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/mutex)[![Latest Stable Version](https://camo.githubusercontent.com/8f5b04615f58617d0511e3a1688837274e41eaf681d89179c38ac9faec0502c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f6d757465782e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/mutex)[![Total Downloads](https://camo.githubusercontent.com/14f3f732202aa9e17807a547e3d9325598fd0d51e3f93f866cbc0c6f4af294fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f6d757465782e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/mutex)[![Licence](https://camo.githubusercontent.com/6b0453c6c3bc4907800aaf3fd2762fb401c4851a5da6b1238e7f3346d90d840b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f6d757465782e737667)](https://camo.githubusercontent.com/6b0453c6c3bc4907800aaf3fd2762fb401c4851a5da6b1238e7f3346d90d840b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f6d757465782e737667)

PHP mutex handling in different ways

Install
-------

[](#install)

Via Composer

```
$ composer require phlib/mutex
```

Usage
-----

[](#usage)

### MySQL

[](#mysql)

```
$adapter = new \Phlib\Db\Adapter([
    'host' => '127.0.0.1',
    'username' => 'my-user',
    'password' => 'my-pass'
]);
$mutex = new \Phlib\Mutex\MySQL('my-lock', $adapter);
if ($mutex->lock()) {
    // Do some data manipulation while locked
    $mutex->unlock();
}
```

### Helpers

[](#helpers)

**Get-Or-Create** provides a simple way to attempt retrieval of a value, or create it using a mutex if it doesn't already exist

```
$getClosure = function() {
    // attempt to get a value, eg. from DB, cache, etc.
    if (!$value) {
        throw new \Phlib\Mutex\NotFoundException();
    }
    return $value;
};

$createClosure = function() {
    // attempt to create a value and write eg. to DB, cache, etc.
    return $value;
};

$value = \Phlib\Mutex\Helper::getOrCreate($mutex, $getClosure, $createClosure);
```

License
-------

[](#license)

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance74

Regular maintenance activity

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 97.4% 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 ~776 days

Recently: every ~969 days

Total

6

Last Release

148d ago

Major Versions

1.0.1 → 2.0.02018-02-28

2.0.0 → 3.0.02021-11-22

PHP version history (3 changes)1.0.0PHP &gt;=5.4.0

2.0.0PHP ^7

3.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/135b7ddf9ec91c412e1b18174f81d1ad2bef66e732624195c156717c96b13731?d=identicon)[letssurf](/maintainers/letssurf)

![](https://www.gravatar.com/avatar/10c53cdcfb3a6d299820aecb993521cc1a972baa09fd8f31d2468908cded7e1d?d=identicon)[chrisminett](/maintainers/chrisminett)

---

Top Contributors

[![chrisminett](https://avatars.githubusercontent.com/u/1084019?v=4)](https://github.com/chrisminett "chrisminett (74 commits)")[![jdempster](https://avatars.githubusercontent.com/u/10297?v=4)](https://github.com/jdempster "jdempster (2 commits)")

---

Tags

mutexphlib

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

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

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

###  Alternatives

[symfony/lock

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

514139.2M692](/packages/symfony-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.

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

PHPackages © 2026

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