PHP client for locker lock server
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
.gitignore
Exceptions.php
Lock.php
Locker.php
README.md

README.md

php-locker - php client for locker lock server

Allows to lock common resources across servers with sub-second precision in php.

Installation

Check out locker server page for server installation instructions.

Just copy Locker.php, Lock.php and Exceptions.php anywhere in your project.

Usage

Look at example/example.php:

require_once('Locker.php');

$Locker = new \Locker\Locker("127.0.0.1", 4545);

// Lock creation
$LockOne = $Locker->createLock('example');

// getting lock
$LockOne->acquire(200, 10000);
// doing very important stuff
echo 'Waiting for 5 seconds..'."\n";
sleep(5);
// releasing lock
$LockOne->release();

API

  • Requiring:

    require_once('/path/to/your/project/Locker.php');
  • New connection:

    $Locker = new \Locker\Locker($host, $port = 4545);
  • Lock creation:

    $Lock = $Locker->createLock($name);
  • Acquiring lock:

    $Lock->acquire($wait, $timeout);
    • $wait - max time to wait for lock (in milliseconds).
    • $timeout - max work time before release call or auto-release by timeout (in milliseconds).
  • Releasing lock:

    $Lock->release($panic = false);

If $panic = true then LockerLostLockException will be fired if time between acquire and release more than $timeout.

For more information look at source files, phpdoc included.