yriveiro / php-fslock
A simple lock implementation using flock.
Installs: 98 208
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=7.0.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1.0
- phpstan/phpstan: ^0.9.2
- phpunit/phpunit: ^6.0.0
This package is auto-updated.
Last update: 2024-10-25 01:24:47 UTC
README
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.