cacheSummary = $cache_summary; return $this; } public function getCacheSummary() { return $this->cacheSummary; } public static function getActiveCacheSpec() { $spec = new PhabricatorDataCacheSpec(); // NOTE: If APCu is installed, it reports that APC is installed. if (extension_loaded('apc') && !extension_loaded('apcu')) { $spec->initAPCSpec(); } else if (extension_loaded('apcu')) { $spec->initAPCuSpec(); } else { $spec->initNoneSpec(); } return $spec; } private function initAPCSpec() { $this ->setName(pht('APC User Cache')) ->setVersion(phpversion('apc')); if (ini_get('apc.enabled')) { $this ->setIsEnabled(true) ->setClearCacheCallback('apc_clear_cache'); $this->initAPCCommonSpec(); } else { $this->setIsEnabled(false); $this->raiseEnableAPCIssue(); } } private function initAPCuSpec() { $this ->setName(pht('APCu')) ->setVersion(phpversion('apcu')); if (ini_get('apc.enabled')) { $this ->setIsEnabled(true) ->setClearCacheCallback('apc_clear_cache'); $this->initAPCCommonSpec(); } else { $this->setIsEnabled(false); $this->raiseEnableAPCIssue(); } } private function initNoneSpec() { if (version_compare(phpversion(), '5.5', '>=')) { $message = pht( 'Installing the "APCu" PHP extension will improve performance.'); $this ->newIssue('extension.apcu') ->setShortName(pht('APCu')) ->setName(pht('PHP Extension "APCu" Not Installed')) ->setMessage($message) ->addPHPExtension('apcu'); } else { $this->raiseInstallAPCIssue(); } } private function initAPCCommonSpec() { $mem = apc_sma_info(); $this->setTotalMemory($mem['num_seg'] * $mem['seg_size']); $info = apc_cache_info('user'); $this->setUsedMemory($info['mem_size']); $this->setEntryCount(count($info['cache_list'])); $cache = $info['cache_list']; $state = array(); foreach ($cache as $item) { $info = idx($item, 'info', ''); $key = self::getKeyPattern($info); if (empty($state[$key])) { $state[$key] = array( 'max' => 0, 'total' => 0, 'count' => 0, ); } $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']); $state[$key]['total'] += $item['mem_size']; $state[$key]['count']++; } $this->setCacheSummary($state); } private static function getKeyPattern($key) { // If this key isn't in the current cache namespace, don't reveal any // information about it. $namespace = PhabricatorEnv::getEnvConfig('phabricator.cache-namespace'); if (strncmp($key, $namespace.':', strlen($namespace) + 1)) { return ''; } $key = preg_replace('/(?