2017 © Pedro Peláez
 

library lock

Simple lock handler for cli applications

image

linio/lock

Simple lock handler for cli applications

  • Friday, July 20, 2018
  • by linio
  • Repository
  • 3 Watchers
  • 2 Stars
  • 459 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 19 % Grown

The README.md

Linio lock

Latest Stable Version License Build Status Scrutinizer Code Quality, (*1)

Linio lock is a small library to handle locks in CLI applications., (*2)

Install

The recommended way to install Linio lock is through composer., (*3)

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

Tests

To run the test suite, you need install the dependencies via composer, then run phpspec., (*4)

$ composer install
$ phpspec run

Usage

The following example shows all the features of linio/lock:, (*5)

<?php

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.
$lock->acquire();

// 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.
        $lock->forceRelease();
    } else {
        // Do not execute the application if it is locked.
        die('Another instance of the application is running');
    }
}

Application::run();

// Release the lock after the execution
$lock->release();

To-do

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

The Versions

20/07 2018

dev-master

9999999-dev

Simple lock handler for cli applications

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.0

 

The Development Requires

lock linio

16/07 2018

dev-dependabot/composer/phpspec/phpspec-tw-3.0|tw-5.0

dev-dependabot/composer/phpspec/phpspec-tw-3.0|tw-5.0

Simple lock handler for cli applications

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.0

 

The Development Requires

lock linio

12/08 2016

0.1.0

0.1.0.0

Simple lock handler for cli applications

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.0

 

The Development Requires

lock linio