Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/cache/spec/PhabricatorCacheSpec.php b/src/applications/cache/spec/PhabricatorCacheSpec.php
index 2a939c6e26..57ef0ebe74 100644
--- a/src/applications/cache/spec/PhabricatorCacheSpec.php
+++ b/src/applications/cache/spec/PhabricatorCacheSpec.php
@@ -1,53 +1,86 @@
<?php
abstract class PhabricatorCacheSpec extends Phobject {
private $name;
private $isEnabled = false;
private $version;
private $issues = array();
+ private $usedMemory = 0;
+ private $totalMemory = 0;
+ private $entryCount = null;
+
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setIsEnabled($is_enabled) {
$this->isEnabled = $is_enabled;
return $this;
}
public function getIsEnabled() {
return $this->isEnabled;
}
public function setVersion($version) {
$this->version = $version;
return $this;
}
public function getVersion() {
return $this->version;
}
protected function newIssue($title, $body, $option = null) {
$issue = array(
'title' => $title,
'body' => $body,
'option' => $option,
);
$this->issues[] = $issue;
return $issue;
}
public function getIssues() {
return $this->issues;
}
+ public function setUsedMemory($used_memory) {
+ $this->usedMemory = $used_memory;
+ return $this;
+ }
+
+ public function getUsedMemory() {
+ return $this->usedMemory;
+ }
+
+ public function setTotalMemory($total_memory) {
+ $this->totalMemory = $total_memory;
+ return $this;
+ }
+
+ public function getTotalMemory() {
+ return $this->totalMemory;
+ }
+
+ public function setEntryCount($entry_count) {
+ $this->entryCount = $entry_count;
+ return $this;
+ }
+
+ public function getEntryCount() {
+ return $this->entryCount;
+ }
+
+
+
}
diff --git a/src/applications/cache/spec/PhabricatorDataCacheSpec.php b/src/applications/cache/spec/PhabricatorDataCacheSpec.php
index 46bebbb01f..ca840c10f8 100644
--- a/src/applications/cache/spec/PhabricatorDataCacheSpec.php
+++ b/src/applications/cache/spec/PhabricatorDataCacheSpec.php
@@ -1,73 +1,84 @@
<?php
final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
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')) {
return self::getAPCSpec($spec);
} else if (extension_loaded('apcu')) {
return self::getAPCuSpec($spec);
} else {
return self::getNoneSpec($spec);
}
}
private static function getAPCSpec(PhabricatorDataCacheSpec $spec) {
$spec
->setName(pht('APC User Cache'))
->setVersion(phpversion('apc'));
if (ini_get('apc.enabled')) {
$spec->setIsEnabled(true);
+ self::getAPCCommonSpec($spec);
} else {
$spec->setIsEnabled(false);
$spec->newIssue(
pht('Enable APC'),
pht(
'The "APC" extension is currently disabled. Set "apc.enabled" to '.
'true to provide caching.'),
'apc.enabled');
}
return $spec;
}
private static function getAPCuSpec(PhabricatorDataCacheSpec $spec) {
$spec
->setName(pht('APCu'))
->setVersion(phpversion('apcu'));
if (ini_get('apc.enabled')) {
$spec->setIsEnabled(true);
+ self::getAPCCommonSpec($spec);
} else {
$spec->setIsEnabled(false);
$spec->newissue(
pht('Enable APCu'),
pht(
'The "APCu" extension is currently disabled. Set '.
'"apc.enabled" to true to provide caching.'),
'apc.enabled');
}
return $spec;
}
private static function getNoneSpec(PhabricatorDataCacheSpec $spec) {
if (version_compare(phpversion(), '5.5', '>=')) {
$spec->newIssue(
pht('Install APCu'),
pht(
'Install the "APCu" PHP extension to provide data caching.'));
} else {
$spec->newIssue(
pht('Install APC'),
pht(
'Install the "APC" PHP extension to provide data caching.'));
}
return $spec;
}
+ private static function getAPCCommonSpec(PhabricatorDataCacheSpec $spec) {
+ $mem = apc_sma_info();
+ $spec->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
+
+ $info = apc_cache_info('user');
+ $spec->setUsedMemory($info['mem_size']);
+ $spec->setEntryCount(count($info['cache_list']));
+ }
+
}
diff --git a/src/applications/cache/spec/PhabricatorOpcodeCacheSpec.php b/src/applications/cache/spec/PhabricatorOpcodeCacheSpec.php
index 0b3dae2863..f829f3640c 100644
--- a/src/applications/cache/spec/PhabricatorOpcodeCacheSpec.php
+++ b/src/applications/cache/spec/PhabricatorOpcodeCacheSpec.php
@@ -1,73 +1,89 @@
<?php
final class PhabricatorOpcodeCacheSpec extends PhabricatorCacheSpec {
public static function getActiveCacheSpec() {
$spec = new PhabricatorOpcodeCacheSpec();
// NOTE: If APCu is installed, it reports that APC is installed.
if (extension_loaded('apc') && !extension_loaded('apcu')) {
return self::getAPCSpec($spec);
} else if (extension_loaded('Zend OPcache')) {
return self::getOpcacheSpec($spec);
} else {
return self::getNoneSpec($spec);
}
}
private static function getAPCSpec(PhabricatorOpcodeCacheSpec $spec) {
$spec
->setName(pht('APC'))
->setVersion(phpversion('apc'));
if (ini_get('apc.enabled')) {
$spec->setIsEnabled(true);
+
+ $mem = apc_sma_info();
+ $spec->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
+
+ $info = apc_cache_info();
+ $spec->setUsedMemory($info['mem_size']);
} else {
$spec->setIsEnabled(false);
$spec->newIssue(
pht('Enable APC'),
pht(
'The "APC" extension is currently disabled. Set "apc.enabled" to '.
'true to improve performance.'),
'apc.enabled');
}
return $spec;
}
private static function getOpcacheSpec(PhabricatorOpcodeCacheSpec $spec) {
$spec
->setName(pht('Zend OPcache'))
->setVersion(phpversion('Zend OPcache'));
if (ini_get('opcache.enable')) {
$spec->setIsEnabled(true);
+
+ $status = opcache_get_status();
+ $memory = $status['memory_usage'];
+
+ $mem_used = $memory['used_memory'];
+ $mem_free = $memory['free_memory'];
+ $mem_junk = $memory['wasted_memory'];
+ $spec->setUsedMemory($mem_used + $mem_junk);
+ $spec->setTotalMemory($mem_used + $mem_junk + $mem_free);
+ $spec->setEntryCount($status['opcache_statistics']['num_cached_keys']);
} else {
$spec->setIsEnabled(false);
$spec->newissue(
pht('Enable Zend OPcache'),
pht(
'The "Zend OPcache" extension is currently disabled. Set '.
'"opcache.enable" to true to improve performance.'),
'opcache.enable');
}
return $spec;
}
private static function getNoneSpec(PhabricatorOpcodeCacheSpec $spec) {
if (version_compare(phpversion(), '5.5', '>=')) {
$spec->newIssue(
pht('Install OPcache'),
pht(
'Install the "Zend OPcache" PHP extension to improve performance.'));
} else {
$spec->newIssue(
pht('Install APC'),
pht(
'Install the "APC" PHP extension to improve performance.'));
}
return $spec;
}
}
diff --git a/src/applications/config/check/PhabricatorAPCSetupCheck.php b/src/applications/config/check/PhabricatorAPCSetupCheck.php
index 62925bbf90..942c797955 100644
--- a/src/applications/config/check/PhabricatorAPCSetupCheck.php
+++ b/src/applications/config/check/PhabricatorAPCSetupCheck.php
@@ -1,88 +1,89 @@
<?php
final class PhabricatorAPCSetupCheck extends PhabricatorSetupCheck {
public function getDefaultGroup() {
return self::GROUP_OTHER;
}
protected function executeChecks() {
if (!extension_loaded('apc')) {
$message = pht(
"Installing the PHP extension 'APC' (Alternative PHP Cache) will ".
"dramatically improve performance. Note that APC versions 3.1.14 and ".
"3.1.15 are broken; 3.1.13 is recommended instead.");
$this
->newIssue('extension.apc')
->setShortName(pht('APC'))
->setName(pht("PHP Extension 'APC' Not Installed"))
->setMessage($message)
->addPHPExtension('apc');
return;
}
if (!ini_get('apc.enabled')) {
$summary = pht('Enabling APC will dramatically improve performance.');
$message = pht(
"The PHP extension 'APC' is installed, but not enabled in your PHP ".
"configuration. Enabling it will dramatically improve Phabricator ".
"performance. Edit the 'apc.enabled' setting to enable the extension.");
$this
->newIssue('extension.apc.enabled')
->setShortName(pht('APC Disabled'))
->setName(pht("PHP Extension 'APC' Not Enabled"))
->setSummary($summary)
->setMessage($message)
->addPHPConfig('apc.enabled');
return;
}
$is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
+ $is_apcu = extension_loaded('apcu');
$is_stat_enabled = ini_get('apc.stat');
$issue_key = null;
- if ($is_stat_enabled && !$is_dev) {
+ if ($is_stat_enabled && !$is_dev && !$is_apcu) {
$issue_key = 'extension.apc.stat-enabled';
$short = pht("'apc.stat' Enabled");
$long = pht("'apc.stat' Enabled in Production");
$summary = pht(
"'apc.stat' is currently enabled, but should probably be disabled.");
$message = pht(
"'apc.stat' is currently enabled in your PHP configuration. For most ".
"Phabricator installs, 'apc.stat' should be disabled. This will ".
"slightly improve performance (PHP will do fewer disk reads) and make ".
"updates safer (PHP won't read in the middle of a 'git pull').\n\n".
"(If you are developing for Phabricator, leave 'apc.stat' enabled but ".
"enable 'phabricator.developer-mode'.)");
- } else if (!$is_stat_enabled && $is_dev) {
+ } else if (!$is_stat_enabled && $is_dev && !$is_apcu) {
$issue_key = 'extension.apc.stat-disabled';
$short = pht("'apc.stat' Disabled");
$long = pht("'apc.stat' Disabled in Development");
$summary = pht(
"'apc.stat' is currently disabled, but should probably be enabled ".
"in development mode.");
$message = pht(
"'apc.stat' is disabled in your PHP configuration, but Phabricator is ".
"set to developer mode. Normally, you should enable 'apc.stat' for ".
"development installs so you don't need to restart your webserver ".
"after making changes to the code.\n\n".
"You can enable 'apc.stat', or disable 'phabricator.developer-mode', ".
"or safely ignore this warning if you have some reasoning behind ".
"your current configuration.");
}
if ($issue_key !== null) {
$this
->newIssue($issue_key)
->setShortName($short)
->setName($long)
->setSummary($summary)
->setMessage($message)
->addPHPConfig('apc.stat')
->addPhabricatorConfig('phabricator.developer-mode');
}
}
}
diff --git a/src/applications/config/controller/PhabricatorConfigCacheController.php b/src/applications/config/controller/PhabricatorConfigCacheController.php
index 0b2577b0d1..a0211d1c84 100644
--- a/src/applications/config/controller/PhabricatorConfigCacheController.php
+++ b/src/applications/config/controller/PhabricatorConfigCacheController.php
@@ -1,122 +1,148 @@
<?php
final class PhabricatorConfigCacheController
extends PhabricatorConfigController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$nav = $this->buildSideNavView();
$nav->selectFilter('cache/');
$title = pht('Cache Status');
$crumbs = $this
->buildApplicationCrumbs()
->addTextCrumb(pht('Cache Status'));
$code_box = $this->renderCodeBox();
$data_box = $this->renderDataBox();
$nav->appendChild(
array(
$crumbs,
$code_box,
$data_box,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
));
}
private function renderCodeBox() {
$cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();
$properties = id(new PHUIPropertyListView());
$this->renderCommonProperties($properties, $cache);
return id(new PHUIObjectBoxView())
->setFormErrors($this->renderIssues($cache->getIssues()))
->setHeaderText(pht('Opcode Cache'))
->addPropertyList($properties);
}
private function renderDataBox() {
$cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
$properties = id(new PHUIPropertyListView());
$this->renderCommonProperties($properties, $cache);
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Data Cache'))
->addPropertyList($properties);
}
private function renderCommonProperties(
PHUIPropertyListView $properties,
PhabricatorCacheSpec $cache) {
if ($cache->getName() !== null) {
$name = $this->renderYes($cache->getName());
} else {
$name = $this->renderNo(pht('None'));
}
$properties->addProperty(pht('Cache'), $name);
if ($cache->getIsEnabled()) {
$enabled = $this->renderYes(pht('Enabled'));
} else {
$enabled = $this->renderNo(pht('Not Enabled'));
}
$properties->addProperty(pht('Enabled'), $enabled);
$version = $cache->getVersion();
if ($version) {
$properties->addProperty(pht('Version'), $this->renderInfo($version));
}
+
+ if ($cache->getName() === null) {
+ return;
+ }
+
+ $mem_total = $cache->getTotalMemory();
+ $mem_used = $cache->getUsedMemory();
+
+ if ($mem_total) {
+ $percent = 100 * ($mem_used / $mem_total);
+
+ $properties->addProperty(
+ pht('Memory Usage'),
+ pht(
+ '%s of %s',
+ phutil_tag('strong', array(), sprintf('%.1f%%', $percent)),
+ phutil_format_bytes($mem_total)));
+ }
+
+ $entry_count = $cache->getEntryCount();
+ if ($entry_count !== null) {
+ $properties->addProperty(
+ pht('Cache Entries'),
+ pht('%s', new PhutilNumber($entry_count)));
+ }
+
}
private function renderIssues(array $issues) {
$result = array();
foreach ($issues as $issue) {
$title = $issue['title'];
$body = $issue['body'];
$result[] = array(
phutil_tag('strong', array(), $title.':'),
' ',
$body,
);
}
return $result;
}
private function renderYes($info) {
return array(
id(new PHUIIconView())->setIconFont('fa-check', 'green'),
' ',
$info,
);
}
private function renderNo($info) {
return array(
id(new PHUIIconView())->setIconFont('fa-times-circle', 'red'),
' ',
$info,
);
}
private function renderInfo($info) {
return array(
id(new PHUIIconView())->setIconFont('fa-info-circle', 'grey'),
' ',
$info,
);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Sep 7, 8:01 AM (5 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
222672
Default Alt Text
(15 KB)

Event Timeline