1. Go to this page and download the library: Download friendsofhyperf/lock library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use FriendsOfHyperf\Lock\Exception\LockTimeoutException;
$lock = lock('foo', 10);
try {
$lock->block(5);
// Lock acquired after waiting maximum of 5 seconds...
} catch (LockTimeoutException $e) {
// Unable to acquire lock...
} finally {
optional($lock)->release();
}
lock('foo', 10)->block(5, function () {
// Lock acquired after waiting maximum of 5 seconds...
});
use FriendsOfHyperf\Lock\Annotation\Lock;
use FriendsOfHyperf\Lock\Driver\LockInterface;
class Foo
{
#[Lock(name:"foo", seconds:10)]
protected LockInterface $lock;
public function bar()
{
$this->lock->get(function () {
// Lock acquired indefinitely and automatically released...
});
}
}