本文整理汇总了PHP中wfIncrStats函数的典型用法代码示例。如果您正苦于以下问题:PHP wfIncrStats函数的具体用法?PHP wfIncrStats怎么用?PHP wfIncrStats使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfIncrStats函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLagTimes
function getLagTimes($serverIndexes, $wiki)
{
wfProfileIn(__METHOD__);
$expiry = 5;
$requestRate = 10;
global $wgMemc;
if (empty($wgMemc)) {
$wgMemc = wfGetMainCache();
}
$masterName = $this->parent->getServerName(0);
$memcKey = wfMemcKey('lag_times', $masterName);
$times = $wgMemc->get($memcKey);
if ($times) {
# Randomly recache with probability rising over $expiry
$elapsed = time() - $times['timestamp'];
$chance = max(0, ($expiry - $elapsed) * $requestRate);
if (mt_rand(0, $chance) != 0) {
unset($times['timestamp']);
wfProfileOut(__METHOD__);
return $times;
}
wfIncrStats('lag_cache_miss_expired');
} else {
wfIncrStats('lag_cache_miss_absent');
}
# Cache key missing or expired
$times = array();
foreach ($serverIndexes as $i) {
if ($i == 0) {
# Master
$times[$i] = 0;
} elseif (false !== ($conn = $this->parent->getAnyOpenConnection($i))) {
$times[$i] = $conn->getLag();
} elseif (false !== ($conn = $this->parent->openConnection($i, $wiki))) {
$times[$i] = $conn->getLag();
}
}
# Add a timestamp key so we know when it was cached
$times['timestamp'] = time();
$wgMemc->set($memcKey, $times, $expiry);
# But don't give the timestamp to the caller
unset($times['timestamp']);
$lagTimes = $times;
wfProfileOut(__METHOD__);
return $lagTimes;
}
示例2: get
function get(&$article, &$user)
{
global $wgCacheEpoch;
$fname = 'ParserCache::get';
wfProfileIn($fname);
$key = $this->getKey($article, $user);
wfDebug("Trying parser cache {$key}\n");
$value = $this->mMemc->get($key);
if (is_object($value)) {
wfDebug("Found.\n");
# Delete if article has changed since the cache was made
$canCache = $article->checkTouched();
$cacheTime = $value->getCacheTime();
$touched = $article->mTouched;
if (!$canCache || $value->expired($touched)) {
if (!$canCache) {
wfIncrStats("pcache_miss_invalid");
wfDebug("Invalid cached redirect, touched {$touched}, epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
} else {
wfIncrStats("pcache_miss_expired");
wfDebug("Key expired, touched {$touched}, epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
}
$this->mMemc->delete($key);
$value = false;
} else {
if (isset($value->mTimestamp)) {
$article->mTimestamp = $value->mTimestamp;
}
wfIncrStats("pcache_hit");
}
} else {
wfDebug("Parser cache miss.\n");
wfIncrStats("pcache_miss_absent");
$value = false;
}
wfProfileOut($fname);
return $value;
}
示例3: loadFromCache
/**
* Try to load file metadata from memcached. Returns true on success.
* @return bool
*/
function loadFromCache()
{
$this->dataLoaded = false;
$this->extraDataLoaded = false;
$key = $this->getCacheKey();
if (!$key) {
return false;
}
$cache = ObjectCache::getMainWANInstance();
$cachedValues = $cache->get($key);
// Check if the key existed and belongs to this version of MediaWiki
if (is_array($cachedValues) && $cachedValues['version'] == MW_FILE_VERSION) {
$this->fileExists = $cachedValues['fileExists'];
if ($this->fileExists) {
$this->setProps($cachedValues);
}
$this->dataLoaded = true;
$this->extraDataLoaded = true;
foreach ($this->getLazyCacheFields('') as $field) {
$this->extraDataLoaded = $this->extraDataLoaded && isset($cachedValues[$field]);
}
}
if ($this->dataLoaded) {
wfIncrStats('image_cache.hit');
} else {
wfIncrStats('image_cache.miss');
}
return $this->dataLoaded;
}
示例4: removeDuplicates
/**
* Remove jobs in the job queue which are duplicates of this job.
* This is deadlock-prone and so starts its own transaction.
*/
function removeDuplicates()
{
if (!$this->removeDuplicates) {
return;
}
$fields = $this->insertFields();
unset($fields['job_id']);
$dbw = wfGetDB(DB_MASTER);
$dbw->begin(__METHOD__);
$dbw->delete('job', $fields, __METHOD__);
$affected = $dbw->affectedRows();
$dbw->commit(__METHOD__);
if ($affected) {
wfIncrStats('job-dup-delete', $affected);
}
}
示例5: addWikiTextTitle
public function addWikiTextTitle($text, &$title, $linestart, $tidy = false)
{
global $wgParser;
wfProfileIn(__METHOD__);
wfIncrStats('pcache_not_possible');
$popts = $this->parserOptions();
$oldTidy = $popts->setTidy($tidy);
$parserOutput = $wgParser->parse($text, $title, $popts, $linestart, true, $this->mRevisionId);
$popts->setTidy($oldTidy);
$this->addParserOutput($parserOutput);
wfProfileOut(__METHOD__);
}
示例6: getParserOutput
/**
* Get a ParserOutput for the given ParserOptions and revision ID.
*
* The parser cache will be used if possible. Cache misses that result
* in parser runs are debounced with PoolCounter.
*
* @since 1.19
* @param ParserOptions $parserOptions ParserOptions to use for the parse operation
* @param null|int $oldid Revision ID to get the text from, passing null or 0 will
* get the current revision (default value)
* @param bool $forceParse Force reindexing, regardless of cache settings
* @return bool|ParserOutput ParserOutput or false if the revision was not found
*/
public function getParserOutput(ParserOptions $parserOptions, $oldid = null, $forceParse = false)
{
$useParserCache = !$forceParse && $this->shouldCheckParserCache($parserOptions, $oldid);
wfDebug(__METHOD__ . ': using parser cache: ' . ($useParserCache ? 'yes' : 'no') . "\n");
if ($parserOptions->getStubThreshold()) {
wfIncrStats('pcache.miss.stub');
}
if ($useParserCache) {
$parserOutput = ParserCache::singleton()->get($this, $parserOptions);
if ($parserOutput !== false) {
return $parserOutput;
}
}
if ($oldid === null || $oldid === 0) {
$oldid = $this->getLatest();
}
$pool = new PoolWorkArticleView($this, $parserOptions, $oldid, $useParserCache);
$pool->execute();
return $pool->getParserOutput();
}
示例7: addWikiTextTitle
function addWikiTextTitle($text, &$title, $linestart)
{
global $wgParser;
$fname = 'OutputPage:addWikiTextTitle';
wfProfileIn($fname);
wfIncrStats('pcache_not_possible');
$parserOutput = $wgParser->parse($text, $title, $this->parserOptions(), $linestart, true, $this->mRevisionId);
$this->addParserOutput($parserOutput);
wfProfileOut($fname);
}
示例8: get
/**
* Retrieve the ParserOutput from ParserCache.
* false if not found or outdated.
*
* @param WikiPage|Article $article
* @param ParserOptions $popts
* @param bool $useOutdated (default false)
*
* @return ParserOutput|bool False on failure
*/
public function get($article, $popts, $useOutdated = false)
{
global $wgCacheEpoch;
$canCache = $article->checkTouched();
if (!$canCache) {
// It's a redirect now
return false;
}
$touched = $article->getTouched();
$parserOutputKey = $this->getKey($article, $popts, $useOutdated);
if ($parserOutputKey === false) {
wfIncrStats('pcache.miss.absent');
return false;
}
$value = $this->mMemc->get($parserOutputKey);
if (!$value) {
wfDebug("ParserOutput cache miss.\n");
wfIncrStats("pcache.miss.absent");
return false;
}
wfDebug("ParserOutput cache found.\n");
// The edit section preference may not be the appropiate one in
// the ParserOutput, as we are not storing it in the parsercache
// key. Force it here. See bug 31445.
$value->setEditSectionTokens($popts->getEditSection());
$wikiPage = method_exists($article, 'getPage') ? $article->getPage() : $article;
if (!$useOutdated && $value->expired($touched)) {
wfIncrStats("pcache.miss.expired");
$cacheTime = $value->getCacheTime();
wfDebug("ParserOutput key expired, touched {$touched}, " . "epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
$value = false;
} elseif ($value->isDifferentRevision($article->getLatest())) {
wfIncrStats("pcache.miss.revid");
$revId = $article->getLatest();
$cachedRevId = $value->getCacheRevisionId();
wfDebug("ParserOutput key is for an old revision, latest {$revId}, cached {$cachedRevId}\n");
$value = false;
} elseif (Hooks::run('RejectParserCacheValue', array($value, $wikiPage, $popts)) === false) {
wfIncrStats('pcache.miss.rejected');
wfDebug("ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n");
$value = false;
} else {
wfIncrStats("pcache.hit");
}
return $value;
}
示例9: getParserOutput
/**
* Lightweight method to get the parser output for a page, checking the parser cache
* and so on. Doesn't consider most of the stuff that Article::view is forced to
* consider, so it's not appropriate to use there.
*
* @since 1.16 (r52326) for LiquidThreads
*
* @param $oldid mixed integer Revision ID or null
*/
public function getParserOutput($oldid = null)
{
global $wgEnableParserCache, $wgUser;
// Should the parser cache be used?
$useParserCache = $wgEnableParserCache && $wgUser->getStubThreshold() == 0 && $this->exists() && $oldid === null;
wfDebug(__METHOD__ . ': using parser cache: ' . ($useParserCache ? 'yes' : 'no') . "\n");
if ($wgUser->getStubThreshold()) {
wfIncrStats('pcache_miss_stub');
}
$parserOutput = false;
if ($useParserCache) {
$parserOutput = ParserCache::singleton()->get($this, $this->getParserOptions());
}
if ($parserOutput === false) {
// Cache miss; parse and output it.
$rev = Revision::newFromTitle($this->getTitle(), $oldid);
return $this->getOutputFromWikitext($rev->getText(), $useParserCache);
} else {
return $parserOutput;
}
}
示例10: getDiffBody
/**
* Get the diff table body, without header
*
* @return mixed
*/
function getDiffBody()
{
global $wgMemc;
$fname = 'DifferenceEngine::getDiffBody';
wfProfileIn($fname);
// Cacheable?
$key = false;
if ($this->mOldid && $this->mNewid) {
$key = wfMemcKey('diff', 'version', MW_DIFF_VERSION, 'oldid', $this->mOldid, 'newid', $this->mNewid);
// Try cache
if (!$this->mRefreshCache) {
$difftext = $wgMemc->get($key);
if ($difftext) {
wfIncrStats('diff_cache_hit');
$difftext = $this->localiseLineNumbers($difftext);
$difftext .= "\n<!-- diff cache key {$key} -->\n";
wfProfileOut($fname);
return $difftext;
}
}
// don't try to load but save the result
} else {
}
// Loadtext is permission safe, this just clears out the diff
if (!$this->loadText()) {
wfProfileOut($fname);
return false;
} else {
if ($this->mOldRev && !$this->mOldRev->userCan(Revision::DELETED_TEXT)) {
return '';
} else {
if ($this->mNewRev && !$this->mNewRev->userCan(Revision::DELETED_TEXT)) {
return '';
}
}
}
$difftext = $this->generateDiffBody($this->mOldtext, $this->mNewtext);
// Save to cache for 7 days
// Only do this for public revs, otherwise an admin can view the diff and a non-admin can nab it!
if ($this->mOldRev && $this->mOldRev->isDeleted(Revision::DELETED_TEXT)) {
wfIncrStats('diff_uncacheable');
} else {
if ($this->mNewRev && $this->mNewRev->isDeleted(Revision::DELETED_TEXT)) {
wfIncrStats('diff_uncacheable');
} else {
if ($key !== false && $difftext !== false) {
wfIncrStats('diff_cache_miss');
$wgMemc->set($key, $difftext, 7 * 86400);
} else {
wfIncrStats('diff_uncacheable');
}
}
}
// Replace line numbers with the text in the user's language
if ($difftext !== false) {
$difftext = $this->localiseLineNumbers($difftext);
}
wfProfileOut($fname);
return $difftext;
}
示例11: loadFromCache
/**
* Try to load video metadata from memcached.
* @return Boolean: true on success.
*/
private function loadFromCache()
{
global $wgMemc;
wfProfileIn(__METHOD__);
$this->dataLoaded = false;
$key = $this->getCacheKey();
$data = $wgMemc->get($key);
if (!empty($data) && is_array($data)) {
$this->url = $data['url'];
$this->type = $data['type'];
$this->submitter_user_id = $data['user_id'];
$this->submitter_user_name = $data['user_name'];
$this->create_date = $data['create_date'];
$this->dataLoaded = true;
$this->exists = true;
}
if ($this->dataLoaded) {
wfDebug("Loaded Video:{$this->name} from cache\n");
wfIncrStats('video_cache_hit');
} else {
wfIncrStats('video_cache_miss');
}
wfProfileOut(__METHOD__);
return $this->dataLoaded;
}
示例12: get
/**
* Retrieve the ParserOutput from ParserCache.
* false if not found or outdated.
*
* @param Article $article
* @param ParserOptions $popts
* @param bool $useOutdated (default false)
*
* @return ParserOutput|bool False on failure
*/
public function get($article, $popts, $useOutdated = false)
{
global $wgCacheEpoch;
wfProfileIn(__METHOD__);
$canCache = $article->checkTouched();
if (!$canCache) {
// It's a redirect now
wfProfileOut(__METHOD__);
return false;
}
$touched = $article->getTouched();
$parserOutputKey = $this->getKey($article, $popts, $useOutdated);
if ($parserOutputKey === false) {
wfIncrStats('pcache_miss_absent');
wfProfileOut(__METHOD__);
return false;
}
$value = $this->mMemc->get($parserOutputKey);
if (!$value) {
wfDebug("ParserOutput cache miss.\n");
wfIncrStats("pcache_miss_absent");
wfProfileOut(__METHOD__);
return false;
}
wfDebug("ParserOutput cache found.\n");
// The edit section preference may not be the appropiate one in
// the ParserOutput, as we are not storing it in the parsercache
// key. Force it here. See bug 31445.
$value->setEditSectionTokens($popts->getEditSection());
if (!$useOutdated && $value->expired($touched)) {
wfIncrStats("pcache_miss_expired");
$cacheTime = $value->getCacheTime();
wfDebug("ParserOutput key expired, touched {$touched}, " . "epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
$value = false;
} elseif ($value->isDifferentRevision($article->getLatest())) {
wfIncrStats("pcache_miss_revid");
$revId = $article->getLatest();
$cachedRevId = $value->getCacheRevisionId();
wfDebug("ParserOutput key is for an old revision, latest {$revId}, cached {$cachedRevId}\n");
$value = false;
} else {
wfIncrStats("pcache_hit");
}
wfProfileOut(__METHOD__);
return $value;
}
示例13: get
/**
* Retrieve the ParserOutput from ParserCache.
* false if not found or outdated.
*
* @param $article Article
* @param $popts ParserOptions
* @param $useOutdated
*
* @return ParserOutput|false
*/
public function get($article, $popts, $useOutdated = false)
{
global $wgCacheEpoch;
wfProfileIn(__METHOD__);
$canCache = $article->checkTouched();
if (!$canCache) {
// It's a redirect now
wfProfileOut(__METHOD__);
return false;
}
$touched = $article->getTouched();
$parserOutputKey = $this->getKey($article, $popts, $useOutdated);
if ($parserOutputKey === false) {
wfIncrStats('pcache_miss_absent');
wfProfileOut(__METHOD__);
return false;
}
$value = $this->mMemc->get($parserOutputKey);
if (self::try116cache && !$value && strpos($value, '*') !== -1) {
wfDebug("New format parser cache miss.\n");
$parserOutputKey = $this->getParserOutputKey($article, $popts->optionsHash(ParserOptions::legacyOptions(), $article->getTitle()));
$value = $this->mMemc->get($parserOutputKey);
}
if (!$value) {
wfDebug("ParserOutput cache miss.\n");
wfIncrStats("pcache_miss_absent");
wfProfileOut(__METHOD__);
return false;
}
wfDebug("ParserOutput cache found.\n");
// The edit section preference may not be the appropiate one in
// the ParserOutput, as we are not storing it in the parsercache
// key. Force it here. See bug 31445.
$value->setEditSectionTokens($popts->getEditSection());
if (!$useOutdated && $value->expired($touched)) {
wfIncrStats("pcache_miss_expired");
$cacheTime = $value->getCacheTime();
wfDebug("ParserOutput key expired, touched {$touched}, epoch {$wgCacheEpoch}, cached {$cacheTime}\n");
$value = false;
} else {
wfIncrStats("pcache_hit");
}
wfProfileOut(__METHOD__);
return $value;
}
示例14: beforePageDisplayHTML
//.........这里部分代码省略.........
}
}
if (self::$enableImages == 1) {
$disableImages = $wgRequest->getCookie('disableImages');
if ($disableImages) {
$wgRequest->response()->setcookie('disableImages', '');
}
$location = str_replace('?enableImages=1', '', str_replace('&enableImages=1', '', $wgRequest->getFullRequestURL()));
$location = str_replace('&mfi=1', '', str_replace('&mfi=0', '', $location));
$location = $this->getRelativeURL($location);
$wgRequest->response()->header('Location: ' . $location . '&mfi=1');
}
self::$format = $wgRequest->getText('format');
self::$callback = $wgRequest->getText('callback');
self::$requestedSegment = $wgRequest->getText('seg', 0);
self::$search = $wgRequest->getText('search');
self::$searchField = $wgRequest->getText('search', '');
$device = new DeviceDetection();
if ($xDevice) {
$formatName = $xDevice;
} else {
$formatName = $device->formatName($userAgent, $acceptHeader);
}
self::$device = $device->format($formatName);
if (self::$device['view_format'] === 'wml') {
$this->contentFormat = 'WML';
} elseif (self::$device['view_format'] === 'html') {
$this->contentFormat = 'XHTML';
}
if (self::$useFormat === 'mobile-wap') {
$this->contentFormat = 'WML';
}
if ($mobileAction == 'leave_feedback') {
echo $this->renderLeaveFeedbackXHTML();
wfProfileOut(__METHOD__);
exit;
}
if ($mobileAction == 'leave_feedback_post') {
$this->getMsg();
$subject = $wgRequest->getText('subject', '');
$message = $wgRequest->getText('message', '');
$token = $wgRequest->getText('edittoken', '');
$title = Title::newFromText(self::$messages['mobile-frontend-feedback-page']);
if ($title->userCan('edit') && !$wgUser->isBlockedFrom($title) && $wgUser->matchEditToken($token)) {
$article = new Article($title, 0);
$rawtext = $article->getRawText();
$rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> ";
$article->doEdit($rawtext, '');
}
$location = str_replace('&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '¬iceid=1&useformat=mobile');
$location = $this->getRelativeURL($location);
$wgRequest->response()->header('Location: ' . $location);
wfProfileOut(__METHOD__);
exit;
}
if ($mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML') {
echo $this->renderDisableMobileSiteXHTML();
wfProfileOut(__METHOD__);
exit;
}
if ($mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML') {
echo $this->renderOptInMobileSiteXHTML();
wfProfileOut(__METHOD__);
exit;
}
if ($mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML') {
echo $this->renderOptOutMobileSiteXHTML();
wfProfileOut(__METHOD__);
exit;
}
if ($mobileAction == 'opt_in_cookie') {
wfIncrStats('mobile.opt_in_cookie_set');
$this->setOptInOutCookie('1');
$this->disableCaching();
$location = wfExpandUrl(Title::newMainPage()->getFullURL(), PROTO_CURRENT);
$wgRequest->response()->header('Location: ' . $location);
}
if ($mobileAction == 'opt_out_cookie') {
$this->setOptInOutCookie('');
}
$this->getMsg();
$this->disableCaching();
$this->sendXDeviceVaryHeader();
$this->sendApplicationVersionVaryHeader();
$this->checkUserStatus();
$this->checkUserLoggedIn();
if (self::$title->isSpecial('Userlogin') && self::$isBetaGroupMember) {
self::$wsLoginToken = $wgRequest->getSessionData('wsLoginToken');
$q = array('action' => 'submitlogin', 'type' => 'login');
$returnToVal = $wgRequest->getVal('returnto');
if ($returnToVal) {
$q['returnto'] = $returnToVal;
}
self::$wsLoginFormAction = self::$title->getLocalURL($q);
}
$this->setDefaultLogo();
ob_start(array($this, 'DOMParse'));
wfProfileOut(__METHOD__);
return true;
}
示例15: getLagTimes
/**
* Get lag time for each DB
* Results are cached for a short time in memcached
*/
function getLagTimes()
{
wfProfileIn(__METHOD__);
$expiry = 5;
$requestRate = 10;
global $wgMemc;
$times = $wgMemc->get(wfMemcKey('lag_times'));
if ($times) {
# Randomly recache with probability rising over $expiry
$elapsed = time() - $times['timestamp'];
$chance = max(0, ($expiry - $elapsed) * $requestRate);
if (mt_rand(0, $chance) != 0) {
unset($times['timestamp']);
wfProfileOut(__METHOD__);
return $times;
}
wfIncrStats('lag_cache_miss_expired');
} else {
wfIncrStats('lag_cache_miss_absent');
}
# Cache key missing or expired
$times = array();
foreach ($this->mServers as $i => $conn) {
if ($i == 0) {
# Master
$times[$i] = 0;
} elseif ($this->openConnection($i)) {
$times[$i] = $this->mConnections[$i]->getLag();
}
}
# Add a timestamp key so we know when it was cached
$times['timestamp'] = time();
$wgMemc->set(wfMemcKey('lag_times'), $times, $expiry);
# But don't give the timestamp to the caller
unset($times['timestamp']);
wfProfileOut(__METHOD__);
return $times;
}