gabriel-peleskei / lock-file
Creating lock file for single instance execution
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/gabriel-peleskei/lock-file
Requires
- php: >=5.6.0
- gabriel-peleskei/interrupt-handler: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6
This package is auto-updated.
Last update: 2025-09-29 02:42:08 UTC
README
Mechanism to create/remove and test a lock file. This allows to run a php script only once (as single instance).
Basic Usage
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;
For use cases with interruptions, look into the /examples folder