Skip to content

bobrik/php-locker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

PHP client for locker lock server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages