foxtech6 / mutexsafe
MutexSafe 将帮助您更有效地使用互斥锁。为不同组件提供不同的互斥锁。此外,您还可以添加自己的锁并在此库中使用。
v1.0
2019-10-08 10:28 UTC
Requires
- php: ^7.1
Requires (Dev)
- predis/predis: ~1.0
This package is auto-updated.
Last update: 2024-10-01 00:16:44 UTC
README
有效地管理锁并加快速度 | 使用 PHP7
- 此库将帮助您更有效地使用互斥锁。
- 为不同的组件提供不同的互斥锁。
- 此外,您还可以添加自己的锁并在此库中使用。
如何使用
$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();