swordev / mutex
Read-write concurrency control
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/swordev/mutex
Requires (Dev)
- phpstan/phpstan: ^0.12.9
- phpunit/phpunit: ^9.1.3
This package is not auto-updated.
Last update: 2025-12-24 12:49:59 UTC
README
Read-write concurrency control
Installation
composer require @swordev/mutex
Usage
File read/write 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
use Swordev\Mutex\FileMutex; $mutex = new FileMutex('key'); $mutex->writeLock(5000);
Contextual lock
use Swordev\Mutex\FileMutex; class Foo { function method() { $mutex = new FileMutex(__CLASS__ . '|' . __FUNCTION__); $mutex->writeLock(); // ... } }
Mutex factory
use Swordev\Mutex\MutexFactory; $mutex = new MutexFactory::create(FileMutex::class, 'key');
Development
Test
composer run test
Analyse
composer run analyse
Author
Juanra GM - https://github.com/juanrgm
Distributed under the MIT license.