Skip to content
This repository was archived by the owner on Apr 17, 2021. It is now read-only.

Latest commit

 

History

History
52 lines (37 loc) · 1.25 KB

File metadata and controls

52 lines (37 loc) · 1.25 KB

Lock

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