Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/cache/spec/PhabricatorOpcodeCacheSpec.php
12242 views
1
<?php
2
3
final class PhabricatorOpcodeCacheSpec extends PhabricatorCacheSpec {
4
5
public static function getActiveCacheSpec() {
6
$spec = new PhabricatorOpcodeCacheSpec();
7
8
// NOTE: If APCu is installed, it reports that APC is installed.
9
if (extension_loaded('apc') && !extension_loaded('apcu')) {
10
$spec->initAPCSpec();
11
} else if (extension_loaded('Zend OPcache')) {
12
$spec->initOpcacheSpec();
13
} else {
14
$spec->initNoneSpec();
15
}
16
17
return $spec;
18
}
19
20
private function initAPCSpec() {
21
$this
22
->setName(pht('APC'))
23
->setVersion(phpversion('apc'));
24
25
if (ini_get('apc.enabled')) {
26
$this
27
->setIsEnabled(true)
28
->setClearCacheCallback('apc_clear_cache');
29
30
$mem = apc_sma_info();
31
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
32
33
$info = apc_cache_info();
34
$this->setUsedMemory($info['mem_size']);
35
36
$write_lock = ini_get('apc.write_lock');
37
$slam_defense = ini_get('apc.slam_defense');
38
39
if (!$write_lock || $slam_defense) {
40
$summary = pht('Adjust APC settings to quiet unnecessary errors.');
41
42
$message = pht(
43
'Some versions of APC may emit unnecessary errors into the '.
44
'error log under the current APC settings. To resolve this, '.
45
'enable "%s" and disable "%s" in your PHP configuration.',
46
'apc.write_lock',
47
'apc.slam_defense');
48
49
$this
50
->newIssue('extension.apc.write-lock')
51
->setShortName(pht('Noisy APC'))
52
->setName(pht('APC Has Noisy Configuration'))
53
->setSummary($summary)
54
->setMessage($message)
55
->addPHPConfig('apc.write_lock')
56
->addPHPConfig('apc.slam_defense');
57
}
58
59
$is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
60
$is_stat_enabled = ini_get('apc.stat');
61
if ($is_stat_enabled && !$is_dev) {
62
$summary = pht(
63
'"%s" is currently enabled, but should probably be disabled.',
64
'apc.stat');
65
66
$message = pht(
67
'The "%s" setting is currently enabled in your PHP configuration. '.
68
'In production mode, "%s" should be disabled. '.
69
'This will improve performance slightly.',
70
'apc.stat',
71
'apc.stat');
72
73
$this
74
->newIssue('extension.apc.stat-enabled')
75
->setShortName(pht('"%s" Enabled', 'apc.stat'))
76
->setName(pht('"%s" Enabled in Production', 'apc.stat'))
77
->setSummary($summary)
78
->setMessage($message)
79
->addPHPConfig('apc.stat')
80
->addPhabricatorConfig('phabricator.developer-mode');
81
} else if (!$is_stat_enabled && $is_dev) {
82
$summary = pht(
83
'"%s" is currently disabled, but should probably be enabled.',
84
'apc.stat');
85
86
$message = pht(
87
'The "%s" setting is currently disabled in your PHP configuration, '.
88
'but this software is running in development mode. This option '.
89
'should normally be enabled in development so you do not need to '.
90
'restart anything after making changes to the code.',
91
'apc.stat');
92
93
$this
94
->newIssue('extension.apc.stat-disabled')
95
->setShortName(pht('"%s" Disabled', 'apc.stat'))
96
->setName(pht('"%s" Disabled in Development', 'apc.stat'))
97
->setSummary($summary)
98
->setMessage($message)
99
->addPHPConfig('apc.stat')
100
->addPhabricatorConfig('phabricator.developer-mode');
101
}
102
} else {
103
$this->setIsEnabled(false);
104
$this->raiseEnableAPCIssue();
105
}
106
}
107
108
private function initOpcacheSpec() {
109
$this
110
->setName(pht('Zend OPcache'))
111
->setVersion(phpversion('Zend OPcache'));
112
113
if (ini_get('opcache.enable')) {
114
$this
115
->setIsEnabled(true)
116
->setClearCacheCallback('opcache_reset');
117
118
$status = opcache_get_status();
119
$memory = $status['memory_usage'];
120
121
$mem_used = $memory['used_memory'];
122
$mem_free = $memory['free_memory'];
123
$mem_junk = $memory['wasted_memory'];
124
$this->setUsedMemory($mem_used + $mem_junk);
125
$this->setTotalMemory($mem_used + $mem_junk + $mem_free);
126
$this->setEntryCount($status['opcache_statistics']['num_cached_keys']);
127
128
$is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
129
130
$validate = ini_get('opcache.validate_timestamps');
131
$freq = ini_get('opcache.revalidate_freq');
132
if ($is_dev && (!$validate || $freq)) {
133
$summary = pht(
134
'OPcache is not configured properly for development.');
135
136
$message = pht(
137
'In development, OPcache should be configured to always reload '.
138
'code so nothing needs to be restarted after making changes. To do '.
139
'this, enable "%s" and set "%s" to 0.',
140
'opcache.validate_timestamps',
141
'opcache.revalidate_freq');
142
143
$this
144
->newIssue('extension.opcache.devmode')
145
->setShortName(pht('OPcache Config'))
146
->setName(pht('OPcache Not Configured for Development'))
147
->setSummary($summary)
148
->setMessage($message)
149
->addPHPConfig('opcache.validate_timestamps')
150
->addPHPConfig('opcache.revalidate_freq')
151
->addPhabricatorConfig('phabricator.developer-mode');
152
} else if (!$is_dev && $validate) {
153
$summary = pht('OPcache is not configured ideally for production.');
154
155
$message = pht(
156
'In production, OPcache should be configured to never '.
157
'revalidate code. This will slightly improve performance. '.
158
'To do this, disable "%s" in your PHP configuration.',
159
'opcache.validate_timestamps');
160
161
$this
162
->newIssue('extension.opcache.production')
163
->setShortName(pht('OPcache Config'))
164
->setName(pht('OPcache Not Configured for Production'))
165
->setSummary($summary)
166
->setMessage($message)
167
->addPHPConfig('opcache.validate_timestamps')
168
->addPhabricatorConfig('phabricator.developer-mode');
169
}
170
} else {
171
$this->setIsEnabled(false);
172
173
$summary = pht('Enabling OPcache will dramatically improve performance.');
174
$message = pht(
175
'The PHP "Zend OPcache" extension is installed, but not enabled in '.
176
'your PHP configuration. Enabling it will dramatically improve '.
177
'performance. Edit the "%s" setting to enable the extension.',
178
'opcache.enable');
179
180
$this->newIssue('extension.opcache.enable')
181
->setShortName(pht('OPcache Disabled'))
182
->setName(pht('Zend OPcache Not Enabled'))
183
->setSummary($summary)
184
->setMessage($message)
185
->addPHPConfig('opcache.enable');
186
}
187
}
188
189
private function initNoneSpec() {
190
if (version_compare(phpversion(), '5.5', '>=')) {
191
$message = pht(
192
'Installing the "Zend OPcache" extension will dramatically improve '.
193
'performance.');
194
195
$this
196
->newIssue('extension.opcache')
197
->setShortName(pht('OPcache'))
198
->setName(pht('Zend OPcache Not Installed'))
199
->setMessage($message)
200
->addPHPExtension('Zend OPcache');
201
} else {
202
$this->raiseInstallAPCIssue();
203
}
204
}
205
}
206
207