PHPackages                             recruiterphp/concurrency - 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. recruiterphp/concurrency

ActiveLibrary

recruiterphp/concurrency
========================

MongoDB-based locking system

v6.0.0(9mo ago)13.1k↓100%1MITPHPPHP ^8.4

Since Mar 28Pushed 8mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (10)Versions (11)Used By (1)

Recruiter PHP Concurrency
=========================

[](#recruiter-php-concurrency)

A MongoDB-based locking system for PHP applications that provides distributed locking mechanisms to coordinate concurrent operations across multiple processes or servers.

Features
--------

[](#features)

- **Distributed Locking**: MongoDB-based locks that work across multiple processes and servers
- **Lock Management**: Acquire, release, refresh, and wait for locks with configurable timeouts
- **Retry Mechanisms**: Built-in retry logic for handling transient failures
- **Process Coordination**: Tools for managing process leadership and coordination
- **Timeout Handling**: Configurable timeouts with patience mechanisms

Requirements
------------

[](#requirements)

- PHP 8.4+
- MongoDB extension
- MongoDB server

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

[](#installation)

```
composer require recruiterphp/concurrency
```

Basic Usage
-----------

[](#basic-usage)

### Creating and Using Locks

[](#creating-and-using-locks)

```
use Recruiter\Concurrency\MongoLock;

// Create a lock instance
$lock = new MongoLock($collection, 'my-resource-id');

try {
    // Acquire lock for 5 minutes
    $lock->acquire(300);

    // Perform your critical operations here

} catch (LockNotAvailableException $e) {
    // Handle case when lock cannot be acquired
} finally {
    // Always release the lock
    $lock->release();
}
```

### Lock Waiting

[](#lock-waiting)

```
// Wait for lock to become available
$lock->wait(
    $polling = 10,           // Check every 10 seconds
    $maximumWaitingTime = 600 // Wait maximum 10 minutes
);
```

### Lock Refresh

[](#lock-refresh)

```
// Extend lock duration
$lock->refresh(600); // Extend for another 10 minutes
```

Core Components
---------------

[](#core-components)

### Lock Interface

[](#lock-interface)

The main `Lock` interface provides:

- `acquire(int $duration)` - Acquire lock for specified duration
- `release(bool $force)` - Release the lock
- `refresh(int $duration)` - Extend lock duration
- `wait(int $polling, int $maximumWaitingTime)` - Wait for lock availability
- `show()` - Get diagnostic information

### Implementations

[](#implementations)

- **MongoLock** - MongoDB-based distributed lock
- **NullLock** - No-op lock for testing/disabled scenarios

### Utilities

[](#utilities)

- **Leadership** - Process leadership coordination
- **Patience/TimeoutPatience** - Timeout handling mechanisms
- **InProcessRetry** - Retry logic for operations
- **PeriodicalCheck** - Periodic status checking

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

[](#development)

The project uses Docker for development. Available make targets:

### Setup

[](#setup)

```
make build          # Build Docker image
make up             # Start services
make down           # Stop services
make install        # Install dependencies
make update         # Update dependencies
```

### Testing

[](#testing)

```
make test           # Run tests (excluding long-running ones)
make test-long      # Run long-running tests only
```

The project includes property-based testing using Eris and traditional unit tests with PHPUnit.

### Code Quality

[](#code-quality)

```
make phpstan        # Run static analysis
make rector         # Run automated refactoring
make fix-cs         # Fix code style issues
```

### Utilities

[](#utilities-1)

```
make shell          # Open shell in PHP container
make logs           # View container logs
make clean          # Clean up containers and volumes
```

Code Quality
------------

[](#code-quality-1)

The project maintains high code quality with:

- **PHPStan** - Static analysis at high levels
- **PHP CS Fixer** - Code style enforcement
- **Rector** - Automated refactoring and upgrades
- **Composer Normalize** - Normalized composer.json

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please ensure all tests pass and code quality checks are satisfied before submitting pull requests.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance62

Regular maintenance activity

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 53.6% 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 ~258 days

Recently: every ~565 days

Total

10

Last Release

273d ago

Major Versions

1.0.0 → 2.0.02019-03-28

2.0.4 → v4.0.02025-08-02

v4.0.0 → v5.0.02025-08-03

v5.0.1 → v6.0.02025-08-08

PHP version history (2 changes)1.0.0PHP ^7.2

v4.0.0PHP ^8.4

### Community

Maintainers

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

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

---

Top Contributors

[![dbellettini](https://avatars.githubusercontent.com/u/325358?v=4)](https://github.com/dbellettini "dbellettini (45 commits)")[![giorgiosironi](https://avatars.githubusercontent.com/u/160299?v=4)](https://github.com/giorgiosironi "giorgiosironi (18 commits)")[![silvadanilo](https://avatars.githubusercontent.com/u/344657?v=4)](https://github.com/silvadanilo "silvadanilo (9 commits)")[![gabrielelana](https://avatars.githubusercontent.com/u/50211?v=4)](https://github.com/gabrielelana "gabrielelana (7 commits)")[![razielgn](https://avatars.githubusercontent.com/u/237493?v=4)](https://github.com/razielgn "razielgn (3 commits)")[![MirkoBonadei](https://avatars.githubusercontent.com/u/233235?v=4)](https://github.com/MirkoBonadei "MirkoBonadei (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/recruiterphp-concurrency/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[doctrine/mongodb-odm

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k23.3M299](/packages/doctrine-mongodb-odm)[alcaeus/mongo-php-adapter

Adapter to provide ext-mongo interface on top of mongo-php-library

46412.3M73](/packages/alcaeus-mongo-php-adapter)[facile-it/mongodb-bundle

Bundle service integration of official \[mongodb/mongo-php-library\](https://github.com/mongodb/mongo-php-library) driver library

38212.1k1](/packages/facile-it-mongodb-bundle)[league/flysystem-gridfs

20498.3k21](/packages/league-flysystem-gridfs)[emag-tech-labs/messenger-mongo-bundle

A Mongo transport for the Symfony Messenger component

16196.8k](/packages/emag-tech-labs-messenger-mongo-bundle)

PHPackages © 2026

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