PHPackages                             phphleb/conductor - 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. phphleb/conductor

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

phphleb/conductor
=================

Mutexes for PHP Framework HLEB2

v2.0.1(1y ago)2251MITPHPPHP &gt;=8.2.0

Since Dec 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phphleb/conductor)[ Packagist](https://packagist.org/packages/phphleb/conductor)[ RSS](/packages/phphleb-conductor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (21)Used By (0)

### Use of mutexes in a project (including projects based on the HLEB2 framework)

[](#use-of-mutexes-in-a-project-including-projects-based-on-the-hleb2-framework)

[![PHP](https://camo.githubusercontent.com/b5d4f7901c58ad1ddfff679966f426cc25a9354bab763846b9a7276c2feab4e0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d626c7565)](https://camo.githubusercontent.com/b5d4f7901c58ad1ddfff679966f426cc25a9354bab763846b9a7276c2feab4e0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d626c7565) [![License: MIT](https://camo.githubusercontent.com/fdf4c838e998efe42a2cfb3c27b8addedc9f7ddd1ecfecc4b19254f784232b7a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542532302846726565292d627269676874677265656e2e737667)](https://github.com/phphleb/hleb/blob/master/LICENSE)

The use of mutexes is worthwhile in cases, when access to any code is to be locked, until it is executed in the current process or the set locking time period expires. For example, repetitive simultaneous API requests can cause a parallel recording one and the same value into the data base. In order to avoid such event, a section of the code responsible for recording is to be transformed by mutex methods. There are only three such mutex methods: `acquire`, `release` and `unlock`.

### FileMutex

[](#filemutex)

```
use \Phphleb\Conductor\FileMutex;

$mutex = new FileMutex();
if ($mutex->acquire('mutex-name', 20)) { // Start blocking
       try {
       // Custom code.

       } catch (\Throwable $e) {
          $mutex->unlock('mutex-name'); // Force unlock
          throw $e;
       }
   } else {
       throw new \Exception('Custom error text.');
   }
if (!$mutex->release('mutex-name')) { // End of blocking
   // Rolling back transactions
}
```

When setting the time period for locking (the second argument `acquire` in seconds), it should be taken into account that, if an active process is unable to unlock the mutex on its own, other processes from the **non-sequential** queue that have addressed to this code will continue working only after this time period has expired. That is why they will be completed, in a case of a long delay, at the web server level by timeout waiting for a response from the script.

#### Installation in a project based on the framework HLEB

[](#installation-in-a-project-based-on-the-framework-hleb)

```
composer require phphleb/conductor
```

Create a console commands `php console mutex/db-stat`, `php console mutex/predis-stat` and `php console mutex/file-stat` to get statistics on active mutexes:

```
php console phphleb/conductor add

composer dump-autoload
```

#### Installation in another project

[](#installation-in-another-project)

Using Composer (or copy the files into the **vendor** folder of the project):

```
$ composer require phphleb/conductor
```

Own configuration (to be installed once):

```
use \Phphleb\Conductor\FileMutex;

$config = new MainConfig(); // implements FileConfigInterface, BaseConfigInterface
$mutex = new FileMutex($config);
```

Files of a mutex type are usually applied only for one backend server; otherwise, you can try to synchronize the folder with the tag files of mutexes. However, if it is possible, it will be better to use mutexes based on storing the tags in the data base.

### DbMutex

[](#dbmutex)

The locks with the stored status in the data bases – similar implementation of mutexes. The same methods – `acquire`, `release` и `unlock` – are used, as well as connecting your own configuration. The difference lies in the class used for initializing the mutex.

```
use \Phphleb\Conductor\DbMutex;

$mutex = new DbMutex();
```

By default, the configuration settings are taken from the `mutex.db.type` (config/database.php).

Supported **MySQL** / **MariaDB** / **PostgreSQL**.

### PredisMutex

[](#predismutex)

Redis is connected in the same way.

```
composer require phphleb/hredis
```

Requires [predis/predis](https://github.com/predis/predis) library.

```
use \Phphleb\Conductor\PredisMutex;

$mutex = new PredisMutex();
```

The configuration will be loaded from the `redis.db.type` setting.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~57 days

Recently: every ~216 days

Total

20

Last Release

539d ago

Major Versions

v1.2.8 → v2.0.02024-01-29

PHP version history (2 changes)v1.0.0PHP &gt;=7.4.0

v2.0.0PHP &gt;=8.2.0

### Community

Maintainers

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

---

Top Contributors

[![phphleb](https://avatars.githubusercontent.com/u/48386098?v=4)](https://github.com/phphleb "phphleb (40 commits)")

---

Tags

phpmutexhleb2

### Embed Badge

![Health badge](/badges/phphleb-conductor/health.svg)

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

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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