source: trunk/htdocs/diagnosis/index.php @ 1182

Last change on this file since 1182 was 1182, checked in by moo, 21 months ago

adds xcache.coredump_type, updated ini example

  • Property svn:eol-style set to native
File size: 12.2 KB
Line 
1<?php
2
3include "../common/common.php";
4include get_language_file("./lang");
5
6$knownUnstablePhpVersions = array(
7        array('=', '5.3.14', 'random corrupt memory on high concurrent'),
8        );
9
10$module = "diagnosis";
11
12$notes = array();
13$activeNote = null;
14function checking($item) // {{{
15{
16    global $activeNote;
17    $activeNote = array('item' => $item);
18}
19// }}}
20function result($type, $result, $suggestion = "") // {{{
21{
22    global $notes, $activeNote;
23    $notes[] = array(
24            'type' => $type
25            , 'result' => ($type != 'skipped' && !$suggestion ? "OK. " : "") . $result
26            , 'suggestion' => $suggestion
27            ) + $activeNote;
28}
29// }}}
30function getCacheInfos() // {{{
31{
32    $phpCacheCount = xcache_count(XC_TYPE_PHP);
33    $varCacheCount = xcache_count(XC_TYPE_VAR);
34
35    $cacheInfos = array();
36    for ($i = 0; $i < $phpCacheCount; $i ++) {
37        $cacheInfo = xcache_info(XC_TYPE_PHP, $i);
38        $cacheInfo['type'] = XC_TYPE_PHP;
39        $cacheInfos[] = $cacheInfo;
40    }
41
42    for ($i = 0; $i < $varCacheCount; $i ++) {
43        $cacheInfo = xcache_info(XC_TYPE_VAR, $i);
44        $cacheInfo['type'] = XC_TYPE_VAR;
45        $cacheInfos[] = $cacheInfo;
46    }
47    return $cacheInfos;
48}
49// }}}
50function getIniFileInfo() // {{{
51{
52    ob_start();
53    phpinfo(INFO_GENERAL);
54    $info = ob_get_clean();
55    ob_start();
56    if (preg_match_all("!<tr>[^<]*<td[^>]*>[^<]*(?:Configuration|ini|Server API)[^<]*</td>[^<]*<td[^>]*>[^<]*</td>[^<]*</tr>!s", $info, $m)) {
57        $iniInfo = '<table class="phpinfo">'
58            . implode('', $m[0])
59            . '</table>';
60    }
61    else {
62        $iniInfo = '';
63    }
64    $loadedIni = '';
65    $iniDirectory = '';
66    if (preg_match('!<td class="v">(.*?\\.ini)!', $info, $m)) {
67        $loadedIni = $m[1];
68    }
69    else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) {
70        $iniDirectory = $m[1];
71    }
72    return array($loadedIni, $iniDirectory, $iniInfo);
73}
74// }}}
75
76$xcacheLoaded = extension_loaded('XCache');
77checking(_T("XCache extension")); // {{{
78if (!$xcacheLoaded) {
79    list($loadedIni, $iniDirectory, $iniInfo) = getIniFileInfo();
80    if ($loadedIni) {
81        echo sprintf(_T("Add extension=xcache.so (or xcache.dll) in %s"), $loadedIni);
82    }
83    else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) {
84        echo sprintf(_T("Please put a php.ini in %s and add extension=xcache.so (or xcache.dll) in it"), $iniDirectory);
85    }
86    else {
87        echo _T("Cannot detect php.ini location");
88    }
89    echo " ", _T("(See above)");
90    result(N_("error"), _T('Not loaded'), ob_get_clean());
91}
92else {
93    result(N_("info"), _T('Loaded'));
94}
95// }}}
96if ($xcacheLoaded) { // {{{ load XCache summary
97    $cacheInfos = getCacheInfos();
98
99    $ooms = 0;
100    $errors = 0;
101    $disabled = 0;
102    $compiling = 0;
103    $readonlyProtection = false;
104    $phpCacheCount = xcache_count(XC_TYPE_PHP);
105    $phpCached = 0;
106    $varCached = 0;
107    foreach ($cacheInfos as $cacheInfo) {
108        $ooms += $cacheInfo['ooms'];
109        $errors += $cacheInfo['errors'];
110        $disabled += $cacheInfo['disabled'] ? 1 : 0;
111        if ($cacheInfo['type'] == XC_TYPE_PHP) {
112            $compiling += $cacheInfo['compiling'] ? 1 : 0;
113            $phpCached += $cacheInfo['cached'];
114        }
115        if ($cacheInfo['type'] == XC_TYPE_VAR && $cacheInfo['cached']) {
116            $varCached += $cacheInfo['cached'];
117        }
118        if ($cacheInfo['can_readonly']) {
119            $readonlyProtection = true;
120        }
121    }
122}
123// }}}
124checking(_T("Enabling PHP Cacher")); // {{{
125if (!$xcacheLoaded) {
126    result(N_("skipped"), "XCache not loaded");
127}
128else if (!ini_get("xcache.size")) {
129    result(N_("error")
130        , _T("Not enabled")
131        , _T("Your PHP pages is not accelerated by XCache. Set xcache.size to non-zero, set xcache.cacher = On")
132        );
133}
134else if (!$phpCached) {
135    result(N_("error")
136        , _T("No php script cached")
137        , _T("Your PHP pages is not accelerated by XCache. Set xcache.cacher = On")
138        );
139}
140else {
141    result(N_("info"), _T('Enabled'));
142}
143// }}}
144checking(_T("PHP Compile Time Error")); // {{{
145if (!$xcacheLoaded) {
146    result(N_("skipped"), "XCache not loaded");
147}
148else if (!$phpCacheCount) {
149    result(N_("skipped"), "XCache PHP cacher not enabled");
150}
151else if ($errors) {
152    result(N_("warning")
153        , _T("Error happened when compiling one or some of your PHP code")
154        , _T("PHP code failed to be compiled cannot be cached. This usually means there was syntax error in your PHP code. Enable PHP error_log to see what parser error is it, fix your code. This warning won't go away until PHP is restarted")
155        );
156}
157else {
158    result(N_("info"), _T('No error happened'));
159}
160// }}}
161checking(_T("Busy Compiling")); // {{{
162if (!$xcacheLoaded) {
163    result(N_("skipped"), "XCache not loaded");
164}
165else if (!$phpCacheCount) {
166    result(N_("skipped"), "XCache PHP cacher not enabled");
167}
168else if ($compiling) {
169    result(N_("warning")
170        , _T("Cache marked as busy for compiling")
171        , _T("It's ok if this status don't stay for long. Otherwise, it could be a sign of PHP crash/coredump, report to XCache devs")
172        );
173}
174else {
175    result(N_("info"), _T('Idle'));
176}
177// }}}
178checking(_T("Enabling VAR Cacher")); // {{{
179if (!$xcacheLoaded) {
180    result(N_("skipped"), "XCache not loaded");
181}
182else if (!ini_get("xcache.var_size")) {
183    result(N_("warning")
184        , _T("Not enabled")
185        , _T("PHP code that use XCache caching backend have to use other caching backend instead. Set xcache.var_size to non-zero if you have any PHP code that can use XCache Data Caching API")
186        );
187}
188else {
189    result(N_("info"), _T('Enabled'));
190
191    checking(_T("Using VAR Cacher")); // {{{
192    if (!$varCached) {
193        result(N_("warning")
194            , _T("No variable data cached")
195            , _T("Var Cacher won't work simply by enabling it."
196                . " PHP code must call XCache APIs like xcache_set() to use it as cache backend. 3rd party web apps may come with XCache support, config it to use XCache as caching backend")
197            );
198    }
199    else {
200        result(N_("info"), _T('Cache in use'));
201    }
202    // }}}
203}
204// }}}
205checking(_T("Cache Size")); // {{{
206if (!$xcacheLoaded) {
207    result(N_("skipped"), "XCache not loaded");
208}
209else if ($ooms) {
210    result(N_("warning")
211        , _T("Out of memory happened when trying to write to cache")
212        , _T("Increase xcache.size and/or xcache.var_size")
213        );
214}
215else {
216    result(N_("info"), _T('Enough'));
217}
218// }}}
219checking(_T("Hash Slots")); // {{{
220if (!$xcacheLoaded) {
221    result(N_("skipped"), "XCache not loaded");
222}
223else {
224    $slotsTooBig = null;
225    $slotsTooSmall = null;
226    foreach ($cacheInfos as $cacheInfo) {
227        if ($cacheInfo['size'] < '1024000' && $cacheInfo['slots'] >= '8192') {
228            $slotsTooBig = $cacheInfo['type'];
229            break;
230        }
231        if ($cacheInfo['slots'] < $cacheInfo['cached'] / 2) {
232            $slotsTooSmall = $cacheInfo['type'];
233            break;
234        }
235    }
236    if (isset($slotsTooBig)) {
237        $prefix = $slotsTooBig == XC_TYPE_PHP ? '' : 'var_';
238        result(N_("warning")
239            , _T("Slots value too big")
240            , sprintf(_T("A very small value is set to %s value and leave %s value is too big.\n"
241                . "Decrease %s if small cache is really what you want"), "xcache.{$prefix}size", "xcache.{$prefix}slots", "xcache.{$prefix}slots")
242            );
243    }
244    else if (isset($slotsTooSmall)) {
245        $prefix = $slotsTooSmall == XC_TYPE_PHP ? '' : 'var_';
246        result(N_("warning")
247            , _T("Slots value too small")
248            , sprintf(_T("So many item are cached. Increase %s to a more proper value"), "xcache.{$prefix}slots")
249            );
250    }
251    else {
252        result(N_("info"), _T('Looks good'));
253    }
254}
255// }}}
256checking(_T("Cache Status")); // {{{
257if (!$xcacheLoaded) {
258    result(N_("skipped"), "XCache not loaded");
259}
260else if ($disabled) {
261    result(N_("warning")
262        , _T("At least one of the caches is disabled. ")
263        , _T("Enable the cache.")
264            . (ini_get("xcache.crash_on_coredump") ? " " . _T("It was disabled by PHP crash/coredump handler or you disabled it manually.") : _T('You disabled it manually.'))
265            . (ini_get("xcache.crash_on_coredump") ? " " . _T("If it was caused by PHP crash/coredump, report to XCache devs") : "")
266        );
267}
268else {
269    result(N_("info"), _T('Idle'));
270}
271// }}}
272
273checking(_T("Coredump Directory")); // {{{
274if (!$xcacheLoaded) {
275    result(N_("skipped"), "XCache not loaded");
276}
277else if (!ini_get("xcache.coredump_directory")) {
278    result(N_("info")
279            , _T("Not enabled")
280            , _T("Enable coredump to save debugging information in case when PHP crash. It can also be enabled in other module like php-fpm beside XCache")
281            );
282}
283else if (ini_get("xcache.coredump_directory")) {
284    $coreDir = ini_get("xcache.coredump_directory");
285    if (substr($coreDir, -1) != DIRECTORY_SEPARATOR) {
286        $coreDir .= DIRECTORY_SEPARATOR;
287    }
288    $coreFiles = glob($coreDir . "core*");
289    if ($coreFiles) {
290        result(N_("error")
291                , _T("Core files found:\n") . implode("\n", $coreFiles)
292                , _T("Disable XCache PHP Cacher (set xcache.size=0), remove the core file(s), then restart PHP. If core file appears again, report call stack backtrace in the core to XCache devs")
293                );
294    }
295    else {
296        result(N_("info")
297                , _T("Enabled")
298                , sprintf(_T("You can see core files if PHP crash in %s if PHP crash"), ini_get("xcache.coredump_directory"))
299                );
300    }
301}
302// }}}
303checking(_T("Readonly Protection")); // {{{
304if (!$xcacheLoaded) {
305    result(N_("skipped"), "XCache not loaded");
306}
307else if (ini_get("xcache.readonly_protection") && !$readonlyProtection) {
308    result(N_("error")
309        , _T("Set to enabled but not available")
310        , _T("Use xcache.mmap_path other than /dev/zero")
311        );
312}
313else {
314    result(N_("info")
315        , $readonlyProtection ? _T("Enabled") : _T("Disabled")
316        , _T("Enable readonly_protection == --performance & ++stability. "
317            . "Disable readonly_protection == ++performance & --stability")
318        );
319}
320// }}}
321checking(_T("XCache modules")); // {{{
322if (!$xcacheLoaded) {
323    result(N_("skipped"), "XCache not loaded");
324}
325else {
326    $xcacheModules = explode(" ", XCACHE_MODULES);
327    $unexpectedModules = array_intersect($xcacheModules, array("coverager", "disassembler"));
328    if ($unexpectedModules) {
329        result(N_("warning")
330            , implode("\n", $unexpectedModules)
331            , _T("Acceptable. Module(s) listed are built into XCache but not for production server.\n"
332                . "Leave it as is if you're feeling good.\n"
333                . "Re-configure XCache with the module(s) disabled if you're strict with server security.")
334            );
335    }
336    else {
337        result(N_("info"), _T('Idle'));
338    }
339}
340// }}}
341checking(_T("XCache test setting")); // {{{
342if (!$xcacheLoaded) {
343    result(N_("skipped"), "XCache not loaded");
344}
345else if ((int) ini_get('xcache.test') == 1) {
346    result(N_("warning")
347        , _T("Enabled")
348        , _T("xcache.test is for testing only, not for server. set it to off")
349        );
350}
351else {
352    result(N_("info"), _T('Disabled'));
353}
354// }}}
355checking(_T("PHP Version")); // {{{
356$phpVersion = phpversion();
357$unstablePhpVersionReason = null;
358foreach ($knownUnstablePhpVersions as $knownUnstablePhpVersion) {
359    list($compareOp, $unstablePhpVersion, $reason) = $knownUnstablePhpVersion;
360    if ($compareOp) {
361        $isUnstable = version_compare($phpVersion, $unstablePhpVersion, $compareOp);
362    }
363    else {
364        $isUnstable = substr($phpVersion, 0, strlen($unstablePhpVersion)) == $unstablePhpVersion;
365    }
366
367    if ($isUnstable) {
368        $unstablePhpVersionReason = $reason;
369        break;
370    }
371}
372if ($unstablePhpVersionReason) {
373    result(N_("error")
374            , _T("The version of PHP you're using is known to be unstable: ") . $unstablePhpVersionReason
375            , _T("Upgrade to new version of PHP"));
376}
377else {
378    result(N_("info"), _T("Looks good"));
379}
380// }}}
381checking(_T("Extension Compatibility")); // {{{
382$loadedZendExtensions = get_loaded_extensions(true);
383$extensionGood = true;
384if (array_search("Zend Optimizer", $loadedZendExtensions) !== false) {
385    result(N_("info")
386        , _T("Zend Optimizer loaded")
387        , _T("Optimizer feature of 'Zend Optimizer' is disabled by XCache due to compatibility reason; the Loader of it is still available, encoded files are still supported")
388        );
389    $extensionGood = false;
390}
391if (array_search("the ionCube PHP Loader", $loadedZendExtensions) !== false) {
392    result(N_("info")
393        , _T("the ionCube PHP Loader loaded")
394        , _T("Compatibility with this the ionCube PHp Loader' is taken care of; But in case if there's any problem, report to ionCube team and/or XCache devs")
395        );
396    $extensionGood = false;
397}
398if (!$extensionGood) {
399    result(N_("info"), _T("Looks good"));
400}
401// }}}
402checking(_T("SAPI Compatibility")); // {{{
403
404if (php_sapi_name() == "cgi" || php_sapi_name() == "cgi-fcgi" && !isset($_SERVER["FCGI_ROLE"])) {
405    result(N_("error"), _T("CGI is not supported"), _T("Use FastCGI or FPM instead"));
406}
407else if (php_sapi_name() == "cgi-fcgi" && isset($_SERVER["FCGI_ROLE"]) && (int) getenv("PHP_FCGI_CHILDREN") < 1) {
408    result(N_("error")
409        , "PHP_FCGI_CHILDREN<1"
410        , _T("PHP_FCGI_CHILDREN should be >= 1 and use 1 group of parent/childs model. See http://xcache.lighttpd.net/wiki/Faq"));
411}
412else {
413    result(N_("info"), _T("Looks good"));
414}
415// }}}
416
417include "./diagnosis.tpl.php";
418
Note: See TracBrowser for help on using the repository browser.