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


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.


Add the following to your composer.json:

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



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

try {

    // Lock successful...

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

} 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 && cd lock/
$ composer install
$ bin/phpspec run