本文整理汇总了PHP中BagOStuff::makeGlobalKey方法的典型用法代码示例。如果您正苦于以下问题:PHP BagOStuff::makeGlobalKey方法的具体用法?PHP BagOStuff::makeGlobalKey怎么用?PHP BagOStuff::makeGlobalKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BagOStuff
的用法示例。
在下文中一共展示了BagOStuff::makeGlobalKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFileContentsHashInternal
/**
* Get a hash of a file's contents, either by retrieving a previously-
* computed hash from the cache, or by computing a hash from the file.
*
* @private
* @param string $filePath Full path to the file.
* @param string $algo Name of selected hashing algorithm.
* @return string|bool Hash of file contents, or false if the file could not be read.
*/
public function getFileContentsHashInternal($filePath, $algo = 'md4')
{
$mtime = filemtime($filePath);
if ($mtime === false) {
return false;
}
$cacheKey = $this->cache->makeGlobalKey(__CLASS__, $filePath, $mtime, $algo);
$hash = $this->cache->get($cacheKey);
if ($hash) {
return $hash;
}
$contents = file_get_contents($filePath);
if ($contents === false) {
return false;
}
$hash = hash($algo, $contents);
$this->cache->set($cacheKey, $hash, 60 * 60 * 24);
// 24h
return $hash;
}
示例2: doWait
/**
* Wait for a given slave to catch up to the master pos stored in $this
* @param int $index Server index
* @param bool $open Check the server even if a new connection has to be made
* @param int $timeout Max seconds to wait; default is mWaitTimeout
* @return bool
*/
protected function doWait($index, $open = false, $timeout = null)
{
$close = false;
// close the connection afterwards
// Check if we already know that the DB has reached this point
$server = $this->getServerName($index);
$key = $this->srvCache->makeGlobalKey(__CLASS__, 'last-known-pos', $server);
/** @var DBMasterPos $knownReachedPos */
$knownReachedPos = $this->srvCache->get($key);
if ($knownReachedPos && $knownReachedPos->hasReached($this->mWaitForPos)) {
wfDebugLog('replication', __METHOD__ . ": slave {$server} known to be caught up (pos >= {$knownReachedPos}).\n");
return true;
}
// Find a connection to wait on, creating one if needed and allowed
$conn = $this->getAnyOpenConnection($index);
if (!$conn) {
if (!$open) {
wfDebugLog('replication', __METHOD__ . ": no connection open for {$server}\n");
return false;
} else {
$conn = $this->openConnection($index, '');
if (!$conn) {
wfDebugLog('replication', __METHOD__ . ": failed to connect to {$server}\n");
return false;
}
// Avoid connection spam in waitForAll() when connections
// are made just for the sake of doing this lag check.
$close = true;
}
}
wfDebugLog('replication', __METHOD__ . ": Waiting for slave {$server} to catch up...\n");
$timeout = $timeout ?: $this->mWaitTimeout;
$result = $conn->masterPosWait($this->mWaitForPos, $timeout);
if ($result == -1 || is_null($result)) {
// Timed out waiting for slave, use master instead
$msg = __METHOD__ . ": Timed out waiting on {$server} pos {$this->mWaitForPos}";
wfDebugLog('replication', "{$msg}\n");
wfDebugLog('DBPerformance', "{$msg}:\n" . wfBacktrace(true));
$ok = false;
} else {
wfDebugLog('replication', __METHOD__ . ": Done\n");
$ok = true;
// Remember that the DB reached this point
$this->srvCache->set($key, $this->mWaitForPos, BagOStuff::TTL_DAY);
}
if ($close) {
$this->closeConnection($conn);
}
return $ok;
}
示例3: __construct
/**
* @param BagOStuff $store
* @param array $client Map of (ip: <IP>, agent: <user-agent>)
* @since 1.27
*/
public function __construct(BagOStuff $store, array $client)
{
$this->store = $store;
$this->client = $client;
$this->key = $store->makeGlobalKey('ChronologyProtector', md5($client['ip'] . "\n" . $client['agent']));
}
示例4: getCacheKey
private function getCacheKey(array $serverIndexes)
{
sort($serverIndexes);
// Lag is per-server, not per-DB, so key on the master DB name
return $this->srvCache->makeGlobalKey('lag-times', self::VERSION, $this->parent->getServerName($this->parent->getWriterIndex()), implode('-', $serverIndexes));
}
示例5: getLagTimeCacheKey
private function getLagTimeCacheKey()
{
$writerIndex = $this->parent->getWriterIndex();
// Lag is per-server, not per-DB, so key on the master DB name
return $this->srvCache->makeGlobalKey('lag-times', $this->parent->getServerName($writerIndex));
}
示例6: getTouchedKey
/**
* @param BagOStuff $store
* @param string $dbName
* @return string
*/
private function getTouchedKey(BagOStuff $store, $dbName)
{
return $store->makeGlobalKey(__CLASS__, 'mtime', $this->clientId, $dbName);
}