boo1ean/semaphore

Don't let your app be afraid of parallel execution

dev-master 2013-12-11 11:07 UTC

This package is not auto-updated.

Last update: 2024-06-04 04:57:43 UTC


README

This package provide simple semaphore wrapper which can work different adapters

Basic usage

<?php

use Semaphore\Semaphore;

$lock = new Semaphore();
$key  = 'oh no!';

if ($lock->locked($key) {
	// Meh, it's so locked...
} else {
	// Lock semaphore
	$lock->lock($key);

	// Do thread-safe operations
	reallyImportantCriticalStuff();

	// Release lock
	$lock->unlock($key);
}