Skip to content

DanCech/redlocker-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redlocker-php

Redlock style Locker distributed locks in PHP

Based on Redlock-rb, redlock-php and php-locker.

This library implements the distributed lock manager algorithm described in this blog post, using the node.js locker server.

Features of locker:

  • Lock timeouts with millisecond precision:
    • Timeout to wait for getting lock.
    • Timeout to keep lock before releae.
  • No polling: one request to acquire, one request to release.
  • Auto-releasing locks on disconnect.
  • Pure node.js. Just awesome.

Features of redlocker-php:

  • Uses non-blocking socket io to obtain distributed locks in parallel
    • Can obtain distributed lock in ~2x the round-trip latency of the (N/2+1)th fastest server

Example usage:

use RedLocker\LockManager;

$servers = array(
  array('localhost','4545'),
  array('localhost','4546'),
  array('localhost','4547'),
);

$manager = new LockManager($servers);

$lockOne = $manager->lock('example', 200, 10000);
if (!$lockOne) {
  echo 'Couldn\'t acquire lock!'."\n";
} else {
  echo 'Got lock, working...'."\n";
  // do stuff
  sleep(5);
  $lockOne->release();
  echo 'Done'."\n";
}

About

Redlock style Locker distributed locks in PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages