This package is abandoned and no longer maintained. No replacement package was suggested.

Simple object-oriented file lock management

v1.0.2 2015-01-07 13:57 UTC

This package is not auto-updated.

Last update: 2021-04-26 10:51:22 UTC


README

Build Status Latest Stable Version License

The standard PHP flock function is difficult to test against. This library provides a modern, object-oriented wrapper to flock.

Installation

Add the following to your composer.json:

{
    "require": {
        "benconstable/lock": "~1.0"
    }
}

Usage

<?php

$lock = new BenConstable\Lock\Lock('/path/to/file.txt');

try {
    $lock->acquire();

    // Lock successful...

    // Release lock. Optional, as resource will also be released automatically
    // when the lock object is destroyed

    $lock->release();
} catch (BenConstable\Lock\Exception\LockException $e) {
    // Lock failed...
}

Development & contribution

To develop and/or contribute to this library, you must add tests for your code. Tests are built with Phpspec. To run them:

$ git clone https://github.com/BenConstable/lock && cd lock/
$ composer install
$ bin/phpspec run