deepeloper / lib-process
PHP-process Lock library
1.0.1
2024-07-01 08:39 UTC
Requires
- php: >=8.2
Requires (Dev)
README
Compatibility
Installing
Run composer require deepeloper/lib-process
.
Usage
use deepeloper\Lib\Process\Lock; use deepeloper\Lib\Process\Lock\Storage; try { $lock = new Lock( Storage::getLayer("Filesystem", ['path' => "path/to/lock"]), 60 * 5, // 5 minutes true, // Destroy previous lock, false by default // "...", // custom lock id ); } catch (RuntimeException $e) { switch ($e->getCode()) { case Lock::EXISTING_IS_VALID: // Previous lock is valid, interrupt process. die; default: throw $e; } } // Long time loop while (true) { // ... try { $lock->update(true); // true to call \set_time_limit(), false by default } catch (RuntimeException $e) { // Lock was destroyed by another instance of the daemon } }