Simple lock handler for cli applications

0.1.0 2016-08-12 00:32 UTC

This package is auto-updated.

Last update: 2020-10-08 01:11:52 UTC


Latest Stable Version License Build Status Scrutinizer Code Quality

Linio lock is a small library to handle locks in CLI applications.


The recommended way to install Linio lock is through composer.

    "require": {
        "linio/lock": "^0.1"


To run the test suite, you need install the dependencies via composer, then run phpspec.

$ composer install
$ phpspec run


The following example shows all the features of linio/lock:


use Linio\Lock\Lock;

// Define options for the forced release.
$options = getopt('f', ['force']);

// Create the lock instance.
$lock = new Lock('lock_name');

// Create the lock file with the pid inside.

// Check if the application is locked.
if ($lock->isLocked()) {
    // If the '-f' or '--force' cli option is set.
    if (isset($options['f']) || isset($options['force'])) {
        // Release the lock killing the running process.
    } else {
        // Do not execute the application if it is locked.
        die('Another instance of the application is running');


// Release the lock after the execution


  • Abstract locking mechanisms, allowing another methods beyond file lock.
  • Properly test the Linio\Lock\Lock class (achievable after the development of the first item)