Skip to content

Commit ffe9c26

Browse files
author
epriestley
committedApr 8, 2015
Emit cache setup issues from cache specs
Summary: Ref T5501. Currently, we emit some bad warnings about, e.g., "apc.stat" on PHP 5.5+ systems with OPcache, where the warnings are not relevant. Generate and raise warnings out of the CacheSpec pipeline so we only run relevant code. Test Plan: Faked various warnings and saw them render correctly. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5501 Differential Revision: https://secure.phabricator.com/D12318
1 parent bc08901 commit ffe9c26

9 files changed

+224
-203
lines changed
 

‎src/__phutil_library_map__.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,6 @@
12621262
'PeopleCreateUsersCapability' => 'applications/people/capability/PeopleCreateUsersCapability.php',
12631263
'PeopleUserLogGarbageCollector' => 'applications/people/garbagecollector/PeopleUserLogGarbageCollector.php',
12641264
'Phabricator404Controller' => 'applications/base/controller/Phabricator404Controller.php',
1265-
'PhabricatorAPCSetupCheck' => 'applications/config/check/PhabricatorAPCSetupCheck.php',
12661265
'PhabricatorAWSConfigOptions' => 'applications/config/option/PhabricatorAWSConfigOptions.php',
12671266
'PhabricatorAccessControlTestCase' => 'applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php',
12681267
'PhabricatorAccessLog' => 'infrastructure/log/PhabricatorAccessLog.php',
@@ -1474,6 +1473,7 @@
14741473
'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php',
14751474
'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php',
14761475
'PhabricatorCacheSchemaSpec' => 'applications/cache/storage/PhabricatorCacheSchemaSpec.php',
1476+
'PhabricatorCacheSetupCheck' => 'applications/config/check/PhabricatorCacheSetupCheck.php',
14771477
'PhabricatorCacheSpec' => 'applications/cache/spec/PhabricatorCacheSpec.php',
14781478
'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php',
14791479
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
@@ -4544,7 +4544,6 @@
45444544
'PeopleCreateUsersCapability' => 'PhabricatorPolicyCapability',
45454545
'PeopleUserLogGarbageCollector' => 'PhabricatorGarbageCollector',
45464546
'Phabricator404Controller' => 'PhabricatorController',
4547-
'PhabricatorAPCSetupCheck' => 'PhabricatorSetupCheck',
45484547
'PhabricatorAWSConfigOptions' => 'PhabricatorApplicationConfigOptions',
45494548
'PhabricatorAccessControlTestCase' => 'PhabricatorTestCase',
45504549
'PhabricatorAccessLogConfigOptions' => 'PhabricatorApplicationConfigOptions',
@@ -4768,6 +4767,7 @@
47684767
'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow',
47694768
'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector',
47704769
'PhabricatorCacheSchemaSpec' => 'PhabricatorConfigSchemaSpec',
4770+
'PhabricatorCacheSetupCheck' => 'PhabricatorSetupCheck',
47714771
'PhabricatorCacheSpec' => 'Phobject',
47724772
'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector',
47734773
'PhabricatorCalendarApplication' => 'PhabricatorApplication',

‎src/applications/cache/spec/PhabricatorCacheSpec.php

+33-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ public function getVersion() {
3838
return $this->version;
3939
}
4040

41-
protected function newIssue($title, $body, $option = null) {
42-
$issue = array(
43-
'title' => $title,
44-
'body' => $body,
45-
'option' => $option,
46-
);
47-
48-
$this->issues[] = $issue;
41+
protected function newIssue($key) {
42+
$issue = id(new PhabricatorSetupIssue())
43+
->setIssueKey($key);
44+
$this->issues[$key] = $issue;
4945

5046
return $issue;
5147
}
@@ -81,6 +77,35 @@ public function getEntryCount() {
8177
return $this->entryCount;
8278
}
8379

80+
protected function raiseInstallAPCIssue() {
81+
$message = pht(
82+
"Installing the PHP extension 'APC' (Alternative PHP Cache) will ".
83+
"dramatically improve performance. Note that APC versions 3.1.14 and ".
84+
"3.1.15 are broken; 3.1.13 is recommended instead.");
85+
86+
return $this
87+
->newIssue('extension.apc')
88+
->setShortName(pht('APC'))
89+
->setName(pht("PHP Extension 'APC' Not Installed"))
90+
->setMessage($message)
91+
->addPHPExtension('apc');
92+
}
8493

94+
protected function raiseEnableAPCIssue() {
95+
$summary = pht('Enabling APC/APCu will improve performance.');
96+
$message = pht(
97+
'The APC or APCu PHP extensions are installed, but not enabled in your '.
98+
'PHP configuration. Enabling these extensions will improve Phabricator '.
99+
'performance. Edit the "apc.enabled" setting to enable these '.
100+
'extensions.');
101+
102+
return $this
103+
->newIssue('extension.apc.enabled')
104+
->setShortName(pht('APC/APCu Disabled'))
105+
->setName(pht('APC/APCu Extensions Not Enabled'))
106+
->setSummary($summary)
107+
->setMessage($message)
108+
->addPHPConfig('apc.enabled');
109+
}
85110

86111
}

‎src/applications/cache/spec/PhabricatorDataCacheSpec.php

+34-45
Original file line numberDiff line numberDiff line change
@@ -15,81 +15,70 @@ public function getCacheSummary() {
1515

1616
public static function getActiveCacheSpec() {
1717
$spec = new PhabricatorDataCacheSpec();
18+
1819
// NOTE: If APCu is installed, it reports that APC is installed.
1920
if (extension_loaded('apc') && !extension_loaded('apcu')) {
20-
return self::getAPCSpec($spec);
21+
$spec->initAPCSpec();
2122
} else if (extension_loaded('apcu')) {
22-
return self::getAPCuSpec($spec);
23+
$spec->initAPCuSpec();
2324
} else {
24-
return self::getNoneSpec($spec);
25+
$spec->initNoneSpec();
2526
}
27+
28+
return $spec;
2629
}
2730

28-
private static function getAPCSpec(PhabricatorDataCacheSpec $spec) {
29-
$spec
31+
private function initAPCSpec() {
32+
$this
3033
->setName(pht('APC User Cache'))
3134
->setVersion(phpversion('apc'));
3235

3336
if (ini_get('apc.enabled')) {
34-
$spec->setIsEnabled(true);
35-
self::getAPCCommonSpec($spec);
37+
$this->setIsEnabled(true);
38+
$this->initAPCCommonSpec();
3639
} else {
37-
$spec->setIsEnabled(false);
38-
$spec->newIssue(
39-
pht('Enable APC'),
40-
pht(
41-
'The "APC" extension is currently disabled. Set "apc.enabled" to '.
42-
'true to provide caching.'),
43-
'apc.enabled');
40+
$this->setIsEnabled(false);
41+
$this->raiseEnableAPCIssue();
4442
}
45-
46-
return $spec;
4743
}
4844

49-
private static function getAPCuSpec(PhabricatorDataCacheSpec $spec) {
50-
$spec
45+
private function initAPCuSpec() {
46+
$this
5147
->setName(pht('APCu'))
5248
->setVersion(phpversion('apcu'));
5349

5450
if (ini_get('apc.enabled')) {
55-
$spec->setIsEnabled(true);
56-
self::getAPCCommonSpec($spec);
51+
$this->setIsEnabled(true);
52+
$this->getAPCCommonSpec();
5753
} else {
58-
$spec->setIsEnabled(false);
59-
$spec->newissue(
60-
pht('Enable APCu'),
61-
pht(
62-
'The "APCu" extension is currently disabled. Set '.
63-
'"apc.enabled" to true to provide caching.'),
64-
'apc.enabled');
54+
$this->setIsEnabled(false);
55+
$this->raiseEnableAPCIssue();
6556
}
66-
67-
return $spec;
6857
}
6958

70-
private static function getNoneSpec(PhabricatorDataCacheSpec $spec) {
59+
private function getNoneSpec() {
7160
if (version_compare(phpversion(), '5.5', '>=')) {
72-
$spec->newIssue(
73-
pht('Install APCu'),
74-
pht(
75-
'Install the "APCu" PHP extension to provide data caching.'));
61+
$message = pht(
62+
'Installing the "APCu" PHP extension will improve performance.');
63+
64+
$this
65+
->newIssue('extension.apcu')
66+
->setShortName(pht('APCu'))
67+
->setName(pht('PHP Extension "APCu" Not Installed'))
68+
->setMessage($message)
69+
->addPHPExtension('apcu');
7670
} else {
77-
$spec->newIssue(
78-
pht('Install APC'),
79-
pht(
80-
'Install the "APC" PHP extension to provide data caching.'));
71+
$this->raiseInstallAPCIssue();
8172
}
82-
83-
return $spec;
8473
}
8574

86-
private static function getAPCCommonSpec(PhabricatorDataCacheSpec $spec) {
75+
private function getAPCCommonSpec() {
8776
$mem = apc_sma_info();
88-
$spec->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
77+
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
8978

9079
$info = apc_cache_info('user');
91-
$spec->setUsedMemory($info['mem_size']);
92-
$spec->setEntryCount(count($info['cache_list']));
80+
$this->setUsedMemory($info['mem_size']);
81+
$this->setEntryCount(count($info['cache_list']));
9382

9483
$cache = $info['cache_list'];
9584
$state = array();
@@ -107,7 +96,7 @@ private static function getAPCCommonSpec(PhabricatorDataCacheSpec $spec) {
10796
$state[$key]['count']++;
10897
}
10998

110-
$spec->setCacheSummary($state);
99+
$this->setCacheSummary($state);
111100
}
112101

113102
private static function getKeyPattern($key) {

0 commit comments

Comments
 (0)
Failed to load comments.