gabriel-peleskei / lock-file
为单实例执行创建锁文件
0.1.1
2018-12-02 20:55 UTC
Requires
- php: >=5.6.0
- gabriel-peleskei/interrupt-handler: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6
This package is auto-updated.
Last update: 2024-09-29 04:31:33 UTC
README
创建/删除和测试锁文件的机制。这允许只运行一次PHP脚本(作为单实例)。
基本用法
use GabrielPeleskei\LockFile\Exception\GeneralException; use GabrielPeleskei\LockFile\Exception\IsLockedException; use GabrielPeleskei\LockFile\LockFile; try { $locker = new LockFile(__DIR__ . '/.basic.lock', []); $locker->start(); // throws if lock file exists echo "Processing...\n"; // do whatever.. // with destructor called, // lockfile should be removed at the end... } catch (IsLockedException $e) { echo "Locked: Process is locked!\n"; exit(1); } catch (GeneralException $e) { // possible write permission problems... echo "EXCEPTION: {$e->getMessage()} ({$e->getCode()})\n"; exit(2); } exit;
对于有中断的使用案例,请查看/example目录