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"
}
}<?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... }
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