本文整理汇总了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);
}