Skip to content

yriveiro/php-fslock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

70310d2 · Jan 5, 2020

History

55 Commits
Oct 1, 2018
Oct 1, 2018
Sep 28, 2013
Oct 1, 2018
Sep 28, 2013
Jan 5, 2020
Jan 5, 2020
Jul 29, 2017
Sep 27, 2013
Oct 1, 2018
Sep 23, 2018
Sep 28, 2018

Repository files navigation

FSLock

Build Status Coverage Status Total Downloads

A simple lock implementation using flock.

NOTE: to use php-backoff with PHP 5.x please use the lastet release of branch 2.x

Usage

use FSLock\FSLock;

$lock = new FSLock('test');

if ($lock->acquire()) {
    // Critical code.

    $lock->release();
}

If you want to use a custom path to store the locks, you should instantiate the FSLock like that

$lock = new FSLock('test', '/tmp/');

API

  • acquire: Acquires the lock, returns true if the operation was successful otherwise the return is false.
  • release: Releases the lock, returns true if the operation was successful otherwise the return is false.
  • id: returns the lock id.
  • getPath: returns the lock path

Install

The recommended way to install this package is through Composer.

composer require yriveiro/php-fslock:3.0.0

Tests

Tests are performed using the phpunit library, to run them:

php vendor/bin/phpunit tests

License

FSLock is licensed under MIT license.