function httprl_acquire_headless_lock in HTTP Parallel Request & Threading Library 6
Same name and namespace in other branches
- 7 httprl.module \httprl_acquire_headless_lock()
Get a floating lock so background calls work.
Parameters
string $name: Name of the lock to use.
int $time: How long the lock will last.
2 calls to httprl_acquire_headless_lock()
- httprl_acquire_lock in ./
httprl.module - Get a lock so background calls work.
- httprl_call_user_func_array_cache in ./
httprl.module - Cache a function; regenerate return value in the background.
File
- ./
httprl.module, line 2370 - HTTP Parallel Request Library module.
Code
function httprl_acquire_headless_lock($name, $time = 60) {
// Acquire lock for this run.
$locked = FALSE;
$lock_counter = 0;
while (!$locked && $lock_counter < 3) {
// Set lock to maximum amount of time.
$locked = lock_acquire($name, $time);
$lock_counter++;
}
if (!$locked) {
return FALSE;
}
// Make sure lock exists after this process is dead.
// Remove from the global locks variable.
unset($GLOBALS['locks'][$name]);
// Remove the lock_id reference in the database.
$lock_inc = httprl_variable_get('lock_inc', './includes/lock.inc');
if ($lock_inc === './includes/lock.inc') {
if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) {
db_update('semaphore')
->fields(array(
'value' => 'httprl',
))
->condition('name', $name)
->condition('value', _lock_id())
->execute();
}
else {
db_query("UPDATE {semaphore} SET value = '%s' WHERE name = '%s' AND value = '%s'", 'httprl', $name, _lock_id());
}
}
elseif (strpos($lock_inc, '/apdqc/apdqc.lock.inc') !== FALSE) {
lock_change_lock_id($name, _lock_id(), 'httprl');
}
return TRUE;
}