A simple lock implementation using flock.
use FSLock\FSLock;
$lock = new FSLock('test');
if ($lock->acquire()) {
// Critical code.
$lock->release();
}
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.destroy
: allows manually destruction of the lock. Internally release the lock and perform a cleanup operation. It's the same process used by the__destruct
magic method.id
: returns the lock id.getPath
: returns the lock path
The recommended way to install this package is through Composer.
composer require yriveiro/php-fslock:2.0.0
Tests are performed using the phpunit
library, to run them:
php vendor/bin/phpunit tests
FSLock is licensed under MIT license.