本文整理汇总了PHP中CCache::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CCache::add方法的具体用法?PHP CCache::add怎么用?PHP CCache::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCache
的用法示例。
在下文中一共展示了CCache::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: acquire
/**
* Acqiure mutex with given name.
* If $timeout is less than zero (which is default) method waits for
* mutex release forever.
* If $timeout is greater than zero, method will wait given amount
* of microseconds for mutex release.
* If $timeout is zero, method will return false immediatly if mutex
* is not free.
*
* @param string $name
* @param int $timeout
* @return bool
*/
public function acquire($name, $timeout = -1)
{
if (isset($this->acqiured[$name])) {
return true;
}
if ($timeout > 0) {
$endTime = microtime(true) + $timeout / 1000000;
}
$lockName = $this->getLockName($name);
$info = $this->getLockInfo();
while ($timeout <= 0 || microtime(true) < $endTime) {
if ($this->cache->add($lockName, $info, $this->expireTime)) {
$this->acqiured[$name] = true;
return true;
}
if ($timeout === 0) {
return false;
}
usleep($this->sleepTime);
}
return false;
}