foxtech6/mutex-locker

此包已被弃用且不再维护。作者建议使用 foxtech6/mutexsafe 包代替。

MutexSafe 将帮助您更有效地使用互斥锁。针对不同组件提供不同的互斥锁。此外,您还可以添加自己的锁并在库中使用。

v1.0 2019-10-08 10:28 UTC

README

高效管理锁 | PHP7 支持

logo

Latest Stable Version Total Downloads License

  • 此库将帮助您更有效地使用互斥锁。
  • 为不同组件提供不同的互斥锁。
  • 此外,您还可以添加自己的锁并在库中使用。

使用方法

$customHandler = new \CustomHandler(/* some parameters */);

// You can send the handler directly to the constructor
$factory = new \Foxtech\Competitor($customHandler);

/* OR */

// via the setHandler method
$factory = new \Foxtech\Competitor();
$factory->setHandler($customHandler);

$timeout = 50;//seconds
$factory->getMutex('mutex_name')->acquire($timeout /* default timeout - 30 seconds */);

// some code

$factory->getMutex('mutex_name')->release();

您还可以将自定义的互斥锁写入自定义处理程序并在我们的库中使用。(重要:您的互斥锁必须实现我们的 接口

$yourCustomHandler = new YourCustomHandler();

$factory = new \Foxtech\Competitor();
$factory->push(YourCustomHandler::class, YourMutex::class);
$factory->setHandler($yourCustomHandler);

$factory->getMutex('mutex_name')->acquire();

// some code

$factory->getMutex('mutex_name')->release();

PDO 处理程序

$pdo = new \PDO('mysql:host=localhost;dbname=test', 'root', 'toor');

$factory = new \Foxtech\Competitor($pdo);

$factory->getMutex('mutex_name')->acquire();

// some code

$factory->getMutex('mutex_name')->release();

许可证

MIT