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

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

geoffroy-aubry/mutex
====================

Mutex &amp; Semaphore PHP implementations both based only on flock() function.

v1.0.1(10y ago)1155LGPL-3.0+PHPPHP &gt;=5.3.3

Since Sep 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/geoffroy-aubry/Mutex)[ Packagist](https://packagist.org/packages/geoffroy-aubry/mutex)[ RSS](/packages/geoffroy-aubry-mutex/feed)WikiDiscussions stable Synced 3w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Mutex
=====

[](#mutex)

[![Latest stable version](https://camo.githubusercontent.com/672449033a8d589f61bf0601bb6f3641373635e223ae2df7f2fa4d652728e842/68747470733a2f2f706f7365722e707567782e6f72672f67656f6666726f792d61756272792f4d757465782f762f737461626c652e706e67 "Latest stable version")](https://packagist.org/packages/geoffroy-aubry/Mutex)

Mutex &amp; Semaphore PHP implementations both based only on flock() function.

Demo
----

[](#demo)

### Mutex

[](#mutex-1)

File: [demo-mutex.php](examples/demo-mutex.php).

Example:

```
$oLogger = new MinimalLogger();
$oMutex = new Mutex($oLogger, 100, '/tmp/demo-lock');

$oMutex->acquire();
echo "Do anything for 3 seconds…\n";
sleep(3);
$oMutex->release();
```

⇒ RESULT for 2 processes P1 and P2:

```
P1 $ php examples/demo-mutex.php
Do anything for 3 seconds…

P2 $ php examples/demo-mutex.php
Waiting to acquire Mutex lock on /tmp/demo-lock…
Mutex lock acquired after 2.57s
Do anything for 3 seconds…
```

### Semaphore

[](#semaphore)

File: [demo-semaphore.php](examples/demo-semaphore.php).

Example, semaphore with 2 units of a resource `/tmp/demo-sem`:

```
$oLogger = new MinimalLogger();
$oSem = new Semaphore($oLogger, 2, 100, '/tmp/demo-sem');

$oSem->acquire();
echo "Do anything for 3 seconds…\n";
sleep(3);
$oSem->release();
```

⇒ RESULT for 3 processes P1, P2 and P3:

```
P1 $ php examples/demo-semaphore.php
Do anything for 3 seconds…

P2 $ php examples/demo-semaphore.php
Do anything for 3 seconds…

P3 $ php examples/demo-semaphore.php
Waiting to acquire lock on /tmp/demo-sem…
Lock acquired after 2.30s
Do anything for 3 seconds…
```

Usage
-----

[](#usage)

**Mutex** is available via [Packagist](https://packagist.org/packages/geoffroy-aubry/mutex).

1. Class autoloading and dependencies are managed by [Composer](http://getcomposer.org/)so install it following the instructions on [Composer: Installation - \*nix](http://getcomposer.org/doc/00-intro.md#installation-nix)or just run the following command:

```
$ curl -sS https://getcomposer.org/installer | php
```

2. Add dependency to `GAubry\Mutex` into require section of your `composer.json`:

```
    {
        "require": {
            "geoffroy-aubry/mutex": "1.*"
        }
    }
```

and run `php composer.phar install` from the terminal into the root folder of your project.

3. Include Composer's autoloader and use the `GAubry\Mutex` classes.

Copyrights &amp; licensing
--------------------------

[](#copyrights--licensing)

Licensed under the GNU Lesser General Public License v3 (LGPL version 3). See [LICENSE](LICENSE) file for details.

Change log
----------

[](#change-log)

See [CHANGELOG](CHANGELOG.md) file for details.

Git branching model
-------------------

[](#git-branching-model)

The git branching model used for development is the one described and assisted by `twgit` tool: .

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Every ~280 days

Total

2

Last Release

3662d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1fcf1fb7a80bf7ddb1bab1b7ee8c4059419000ec8b80a4d532d31d45410cf70?d=identicon)[geoffroy-aubry](/maintainers/geoffroy-aubry)

---

Top Contributors

[![geoffroy-aubry](https://avatars.githubusercontent.com/u/1247448?v=4)](https://github.com/geoffroy-aubry "geoffroy-aubry (8 commits)")

---

Tags

semaphoremutexflock

### Embed Badge

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

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

###  Alternatives

[symfony/lock

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

514135.1M625](/packages/symfony-lock)[malkusch/lock

Mutex library for exclusive code execution.

9479.9M28](/packages/malkusch-lock)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k42](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

749284.3k35](/packages/civicrm-civicrm-core)[symfony/semaphore

Symfony Semaphore Component

374.0M12](/packages/symfony-semaphore)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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