Read-write concurrency control
composer require @swordev/mutex
use Swordev\Mutex\FileMutex;
$mutex1 = new FileMutex('key');
$mutex2 = new FileMutex('key');
$mutex1->readLock(); // true
$mutex2->writeLock(); // false
$mutex1->unlock(); // true
$mutex2->writeLock(); // true
use Swordev\Mutex\FileMutex;
$mutex = new FileMutex('key');
$mutex->writeLock(5000);
use Swordev\Mutex\FileMutex;
class Foo {
function method() {
$mutex = new FileMutex(__CLASS__ . '|' . __FUNCTION__);
$mutex->writeLock();
// ...
}
}
use Swordev\Mutex\MutexFactory;
$mutex = new MutexFactory::create(FileMutex::class, 'key');
composer run test
composer run analyse
Juanra GM - https://github.com/juanrgm
Distributed under the MIT license.