本文整理匯總了PHP中Lock::executeOnce方法的典型用法代碼示例。如果您正苦於以下問題:PHP Lock::executeOnce方法的具體用法?PHP Lock::executeOnce怎麽用?PHP Lock::executeOnce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Lock
的用法示例。
在下文中一共展示了Lock::executeOnce方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: buildDataBackend
/**
* Builds a configured data backend.
*
* If configured this method would automatically install the backend. I.e. a first
* call will take some amount of time.
*
* @return DataBackend
* @throws DataBackendException
*/
private function buildDataBackend()
{
$configuration = ConfigurationRegistry::getConfiguration();
$backend = $this->makeDataBackend();
// Installation
if ($configuration->isAutomaticInstallation() && !$backend->isInstalled()) {
$lock = new Lock(self::INSTALL_LOCK);
$lock->executeOnce(function () use($backend) {
$backend->install();
});
}
// Update hook
register_shutdown_function(array($this, "applyUpdatePlan"), $backend);
return $backend;
}
示例2: testExecuteOnce
/**
* Tests executeOnce().
*
* @see Lock::executeOnce()
*/
public function testExecuteOnce()
{
$name = __FUNCTION__;
$isExecuted = false;
$isExecutedCheck = false;
$lock = new Lock($name);
$lock->executeOnce(function () use(&$isExecuted, &$isExecutedCheck, $name) {
$isExecuted = true;
$checkLock = new Lock($name);
$checkLock->nonblockingExecuteOnce(function () use(&$isExecutedCheck) {
$isExecutedCheck = true;
});
});
$this->assertTrue($isExecuted);
$this->assertFalse($isExecutedCheck);
}