2015-04-07 23:38:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
|
|
|
|
|
2015-04-08 01:00:18 +02:00
|
|
|
private $cacheSummary;
|
|
|
|
|
|
|
|
public function setCacheSummary(array $cache_summary) {
|
|
|
|
$this->cacheSummary = $cache_summary;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheSummary() {
|
|
|
|
return $this->cacheSummary;
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
public static function getActiveCacheSpec() {
|
|
|
|
$spec = new PhabricatorDataCacheSpec();
|
2015-04-08 20:31:01 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
// NOTE: If APCu is installed, it reports that APC is installed.
|
|
|
|
if (extension_loaded('apc') && !extension_loaded('apcu')) {
|
2015-04-08 20:31:01 +02:00
|
|
|
$spec->initAPCSpec();
|
2015-04-07 23:38:03 +02:00
|
|
|
} else if (extension_loaded('apcu')) {
|
2015-04-08 20:31:01 +02:00
|
|
|
$spec->initAPCuSpec();
|
2015-04-07 23:38:03 +02:00
|
|
|
} else {
|
2015-04-08 20:31:01 +02:00
|
|
|
$spec->initNoneSpec();
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
2015-04-08 20:31:01 +02:00
|
|
|
|
|
|
|
return $spec;
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 20:31:01 +02:00
|
|
|
private function initAPCSpec() {
|
|
|
|
$this
|
2015-04-07 23:38:03 +02:00
|
|
|
->setName(pht('APC User Cache'))
|
|
|
|
->setVersion(phpversion('apc'));
|
|
|
|
|
|
|
|
if (ini_get('apc.enabled')) {
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setIsEnabled(true);
|
|
|
|
$this->initAPCCommonSpec();
|
2015-04-07 23:38:03 +02:00
|
|
|
} else {
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setIsEnabled(false);
|
|
|
|
$this->raiseEnableAPCIssue();
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 20:31:01 +02:00
|
|
|
private function initAPCuSpec() {
|
|
|
|
$this
|
2015-04-07 23:38:03 +02:00
|
|
|
->setName(pht('APCu'))
|
|
|
|
->setVersion(phpversion('apcu'));
|
|
|
|
|
|
|
|
if (ini_get('apc.enabled')) {
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setIsEnabled(true);
|
2015-04-08 20:32:30 +02:00
|
|
|
$this->initAPCCommonSpec();
|
2015-04-07 23:38:03 +02:00
|
|
|
} else {
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setIsEnabled(false);
|
|
|
|
$this->raiseEnableAPCIssue();
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 03:01:58 +02:00
|
|
|
private function initNoneSpec() {
|
2015-04-07 23:38:03 +02:00
|
|
|
if (version_compare(phpversion(), '5.5', '>=')) {
|
2015-04-08 20:31:01 +02:00
|
|
|
$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');
|
2015-04-07 23:38:03 +02:00
|
|
|
} else {
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->raiseInstallAPCIssue();
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 20:32:30 +02:00
|
|
|
private function initAPCCommonSpec() {
|
2015-04-08 00:08:47 +02:00
|
|
|
$mem = apc_sma_info();
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
|
2015-04-08 00:08:47 +02:00
|
|
|
|
|
|
|
$info = apc_cache_info('user');
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setUsedMemory($info['mem_size']);
|
|
|
|
$this->setEntryCount(count($info['cache_list']));
|
2015-04-08 01:00:18 +02:00
|
|
|
|
|
|
|
$cache = $info['cache_list'];
|
|
|
|
$state = array();
|
|
|
|
foreach ($cache as $item) {
|
|
|
|
$key = self::getKeyPattern($item['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']++;
|
|
|
|
}
|
|
|
|
|
2015-04-08 20:31:01 +02:00
|
|
|
$this->setCacheSummary($state);
|
2015-04-08 01:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 '<other-namespace>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = preg_replace('/(?<![a-zA-Z])\d+(?![a-zA-Z])/', 'N', $key);
|
|
|
|
$key = preg_replace('/PHID-[A-Z]{4}-[a-z0-9]{20}/', 'PHID', $key);
|
|
|
|
|
|
|
|
// TODO: We should probably standardize how digests get embedded into cache
|
|
|
|
// keys to make this rule more generic.
|
|
|
|
$key = preg_replace('/:celerity:.*$/', ':celerity:X', $key);
|
|
|
|
$key = preg_replace('/:pkcs8:.*$/', ':pkcs8:X', $key);
|
|
|
|
|
|
|
|
return $key;
|
2015-04-08 00:08:47 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|