1. Go to this page and download the library: Download roadrunner-php/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/ */
roadrunner-php / lock example snippets
use RoadRunner\Lock\Lock;
use Spiral\Goridge\RPC\RPC;
;
$id = $lock->lock('pdf:create', ttl: 10);
if ($id === false) {
// The resource is locked by another process
return;
}
try {
// Do the work
} finally {
$lock->release('pdf:create', $id);
}
$id = $lock->lock('pdf:create');
// Acquire lock with ttl - 10 seconds
$id = $lock->lock('pdf:create', ttl: 10);
// or
$id = $lock->lock('pdf:create', ttl: new \DateInterval('PT10S'));
// Acquire lock and wait 5 seconds until lock will be released
$id = $lock->lock('pdf:create', waitTTL: 5);
// or
$id = $lock->lock('pdf:create', waitTTL: new \DateInterval('PT5S'));
// Acquire lock with id - 14e1b600-9e97-11d8-9f32-f2801f1b9fd1
$id = $lock->lock('pdf:create', id: '14e1b600-9e97-11d8-9f32-f2801f1b9fd1');
$id = $lock->lockRead('pdf:create', ttl: 10);
// or
$id = $lock->lockRead('pdf:create', ttl: new \DateInterval('PT10S'));
// Acquire lock and wait 5 seconds until lock will be released
$id = $lock->lockRead('pdf:create', waitTTL: 5);
// or
$id = $lock->lockRead('pdf:create', waitTTL: new \DateInterval('PT5S'));
// Acquire lock with id - 14e1b600-9e97-11d8-9f32-f2801f1b9fd1
$id = $lock->lockRead('pdf:create', id: '14e1b600-9e97-11d8-9f32-f2801f1b9fd1');
// Release lock after task is done.
$lock->release('pdf:create', $id);
// Force release lock
$lock->forceRelease('pdf:create');
if ($lock->exists('pdf:create')) {
// The resource is locked
}
if ($lock->exists('pdf:create', $id)) {
// The lock with this id is held
}
// Set the lock ttl to 10 seconds
$lock->updateTTL('pdf:create', $id, 10);
// or
$lock->updateTTL('pdf:create', $id, new \DateInterval('PT10S'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.