diego.sorrentino / lock
Lock system for procedures
README
Including this library you can create a simple lock for your cron'd scripts that must be executed just one at time.
You can set an expire time (in minutes) for the process and, on next run, the lock-library checks if the previous script is expired, and must be killed, or this execution have to wait.
Install and usage
Install via composer:
$ composer require diego.sorrentino/lock
and autoload and use in your script:
require_once __DIR__ . '/vendor/autoload.php';
$lock = new Lock('processname', './lock', 10);
if ( ! $lock->acquired() )
exit();
//do something
$lock->release();
The library try to create the ./lock/ directory, with the file processname.lock containing the PID of the process, safe for 10 minutes. If next script runs before 10 minute, simply terminate, otherwise kill the PID contained in ./lock/processname.lock
Technical documentation
You can find documentation, automatically created by PHPDocumentor here: http://diego.sorrentino.gitpages.rm.ingv.it/lock/phpdoc
Test and Deploy
Tests are realized using PHPUnit. You can find code coverage here: http://diego.sorrentino.gitpages.rm.ingv.it/lock/coverage
Contributing
If you want to contribute, please use pull requests. To get a best integration, please code using Test Driven Development (TDD) and Calisthenic Programming.
Authors and acknowledgment
Diego Sorrentino, Istituto Nazionale di Geofisica e Vulcanologia, https://www.ingv.it/organizzazione/chi-siamo/personale/#922
License
GPL v3
Project status
Development in progress