[1089] | 1 | <?php |
---|
| 2 | |
---|
| 3 | include "../common/common.php"; |
---|
[1099] | 4 | include get_language_file("./lang"); |
---|
| 5 | |
---|
[1092] | 6 | $knownUnstablePhpVersions = array( |
---|
| 7 | array('=', '5.3.14', 'random corrupt memory on high concurrent'), |
---|
| 8 | ); |
---|
[1089] | 9 | |
---|
| 10 | $module = "diagnosis"; |
---|
| 11 | |
---|
| 12 | $notes = array(); |
---|
[1092] | 13 | $activeNote = null; |
---|
| 14 | function checking($item) // {{{ |
---|
[1089] | 15 | { |
---|
[1092] | 16 | global $activeNote; |
---|
| 17 | $activeNote = array('item' => $item); |
---|
| 18 | } |
---|
| 19 | // }}} |
---|
| 20 | function result($type, $result, $suggestion = "") // {{{ |
---|
| 21 | { |
---|
| 22 | global $notes, $activeNote; |
---|
[1089] | 23 | $notes[] = array( |
---|
| 24 | 'type' => $type |
---|
[1092] | 25 | , 'result' => ($type != 'skipped' && !$suggestion ? "OK. " : "") . $result |
---|
[1089] | 26 | , 'suggestion' => $suggestion |
---|
[1092] | 27 | ) + $activeNote; |
---|
[1089] | 28 | } |
---|
[1090] | 29 | // }}} |
---|
[1089] | 30 | function 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 | } |
---|
[1090] | 49 | // }}} |
---|
[1092] | 50 | function getIniFileInfo() // {{{ |
---|
| 51 | { |
---|
[1090] | 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)) { |
---|
[1092] | 57 | $iniInfo = '<table class="phpinfo">' |
---|
| 58 | . implode('', $m[0]) |
---|
| 59 | . '</table>'; |
---|
[1090] | 60 | } |
---|
[1092] | 61 | else { |
---|
| 62 | $iniInfo = ''; |
---|
| 63 | } |
---|
| 64 | $loadedIni = ''; |
---|
| 65 | $iniDirectory = ''; |
---|
[1090] | 66 | if (preg_match('!<td class="v">(.*?\\.ini)!', $info, $m)) { |
---|
[1092] | 67 | $loadedIni = $m[1]; |
---|
[1090] | 68 | } |
---|
| 69 | else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) { |
---|
[1092] | 70 | $iniDirectory = $m[1]; |
---|
[1090] | 71 | } |
---|
[1092] | 72 | return array($loadedIni, $iniDirectory, $iniInfo); |
---|
| 73 | } |
---|
| 74 | // }}} |
---|
| 75 | |
---|
| 76 | $xcacheLoaded = extension_loaded('XCache'); |
---|
| 77 | checking(_T("XCache extension")); // {{{ |
---|
| 78 | if (!$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 | } |
---|
[1090] | 86 | else { |
---|
[1103] | 87 | echo _T("Cannot detect php.ini location"); |
---|
[1090] | 88 | } |
---|
[1103] | 89 | echo " ", _T("(See above)"); |
---|
| 90 | result(N_("error"), _T('Not loaded'), ob_get_clean()); |
---|
[1090] | 91 | } |
---|
| 92 | else { |
---|
[1103] | 93 | result(N_("info"), _T('Loaded')); |
---|
[1092] | 94 | } |
---|
| 95 | // }}} |
---|
| 96 | if ($xcacheLoaded) { // {{{ load XCache summary |
---|
[1090] | 97 | $cacheInfos = getCacheInfos(); |
---|
[1089] | 98 | |
---|
[1092] | 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; |
---|
[1090] | 107 | foreach ($cacheInfos as $cacheInfo) { |
---|
[1092] | 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']; |
---|
[1090] | 114 | } |
---|
[1092] | 115 | if ($cacheInfo['type'] == XC_TYPE_VAR && $cacheInfo['cached']) { |
---|
| 116 | $varCached += $cacheInfo['cached']; |
---|
| 117 | } |
---|
| 118 | if ($cacheInfo['can_readonly']) { |
---|
| 119 | $readonlyProtection = true; |
---|
| 120 | } |
---|
[1090] | 121 | } |
---|
[1092] | 122 | } |
---|
| 123 | // }}} |
---|
| 124 | checking(_T("Enabling PHP Cacher")); // {{{ |
---|
| 125 | if (!$xcacheLoaded) { |
---|
[1103] | 126 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 127 | } |
---|
| 128 | else if (!ini_get("xcache.size")) { |
---|
[1103] | 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") |
---|
[1092] | 132 | ); |
---|
| 133 | } |
---|
| 134 | else if (!$phpCached) { |
---|
[1103] | 135 | result(N_("error") |
---|
| 136 | , _T("No php script cached") |
---|
| 137 | , _T("Your PHP pages is not accelerated by XCache. Set xcache.cacher = On") |
---|
[1092] | 138 | ); |
---|
| 139 | } |
---|
| 140 | else { |
---|
[1103] | 141 | result(N_("info"), _T('Enabled')); |
---|
[1092] | 142 | } |
---|
| 143 | // }}} |
---|
| 144 | checking(_T("PHP Compile Time Error")); // {{{ |
---|
| 145 | if (!$xcacheLoaded) { |
---|
[1103] | 146 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 147 | } |
---|
| 148 | else if (!$phpCacheCount) { |
---|
[1103] | 149 | result(N_("skipped"), "XCache PHP cacher not enabled"); |
---|
[1092] | 150 | } |
---|
| 151 | else if ($errors) { |
---|
[1103] | 152 | result(N_("warning") |
---|
[1092] | 153 | , _T("Error happened when compiling at least one of your PHP code") |
---|
| 154 | , _T("This usually means there is syntax error in your PHP code. Enable PHP error_log to see what parser error is it, fix your code") |
---|
| 155 | ); |
---|
| 156 | } |
---|
| 157 | else { |
---|
[1103] | 158 | result(N_("info"), _T('No error happened')); |
---|
[1092] | 159 | } |
---|
| 160 | // }}} |
---|
| 161 | checking(_T("Busy Compiling")); // {{{ |
---|
| 162 | if (!$xcacheLoaded) { |
---|
[1103] | 163 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 164 | } |
---|
| 165 | else if (!$phpCacheCount) { |
---|
[1103] | 166 | result(N_("skipped"), "XCache PHP cacher not enabled"); |
---|
[1092] | 167 | } |
---|
| 168 | else if ($compiling) { |
---|
[1103] | 169 | result(N_("warning") |
---|
[1092] | 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 | } |
---|
| 174 | else { |
---|
[1103] | 175 | result(N_("info"), _T('Idle')); |
---|
[1092] | 176 | } |
---|
| 177 | // }}} |
---|
| 178 | checking(_T("Enabling VAR Cacher")); // {{{ |
---|
| 179 | if (!$xcacheLoaded) { |
---|
[1103] | 180 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 181 | } |
---|
| 182 | else if (!ini_get("xcache.var_size")) { |
---|
[1103] | 183 | result(N_("error") |
---|
| 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") |
---|
[1092] | 186 | ); |
---|
| 187 | } |
---|
| 188 | else { |
---|
[1103] | 189 | result(N_("info"), _T('Enabled')); |
---|
[1092] | 190 | |
---|
| 191 | checking(_T("Using VAR Cacher")); // {{{ |
---|
[1103] | 192 | if (!$varCached) { |
---|
| 193 | result(N_("warning") |
---|
[1092] | 194 | , _T("No variable data cached") |
---|
| 195 | , _T("Var Cacher won't work simply by enabling it." |
---|
[1103] | 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") |
---|
[1089] | 197 | ); |
---|
| 198 | } |
---|
[1090] | 199 | else { |
---|
[1103] | 200 | result(N_("info"), _T('Cache in use')); |
---|
[1090] | 201 | } |
---|
[1092] | 202 | // }}} |
---|
| 203 | } |
---|
| 204 | // }}} |
---|
| 205 | checking(_T("Cache Size")); // {{{ |
---|
| 206 | if (!$xcacheLoaded) { |
---|
[1103] | 207 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 208 | } |
---|
| 209 | else if ($ooms) { |
---|
[1103] | 210 | result(N_("warning") |
---|
[1092] | 211 | , _T("Out of memory happened when trying to write to cache") |
---|
| 212 | , _T("Increase xcache.size and/or xcache.var_size") |
---|
| 213 | ); |
---|
| 214 | } |
---|
| 215 | else { |
---|
[1103] | 216 | result(N_("info"), _T('Enough')); |
---|
[1092] | 217 | } |
---|
| 218 | // }}} |
---|
[1103] | 219 | checking(_T("Hash Slots")); // {{{ |
---|
[1092] | 220 | $slotsTooBig = null; |
---|
| 221 | $slotsTooSmall = null; |
---|
| 222 | foreach ($cacheInfos as $cacheInfo) { |
---|
| 223 | if ($cacheInfo['size'] < '1024000' && $cacheInfo['slots'] >= '8192') { |
---|
| 224 | $slotsTooBig = $cacheInfo['type']; |
---|
| 225 | break; |
---|
| 226 | } |
---|
| 227 | if ($cacheInfo['slots'] < $cacheInfo['cached'] / 2) { |
---|
| 228 | $slotsTooSmall = $cacheInfo['type']; |
---|
| 229 | break; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | if (isset($slotsTooBig)) { |
---|
| 233 | $prefix = $slotsTooBig == XC_TYPE_PHP ? '' : 'var_'; |
---|
[1103] | 234 | result(N_("warning") |
---|
[1092] | 235 | , _T("Slots value too big") |
---|
| 236 | , sprintf(_T("A very small value is set to %s value and leave %s value is too big.\n" |
---|
| 237 | . "Decrease %s if small cache is really what you want"), "xcache.{$prefix}size", "xcache.{$prefix}slots", "xcache.{$prefix}slots") |
---|
| 238 | ); |
---|
| 239 | } |
---|
| 240 | else if (isset($slotsTooSmall)) { |
---|
| 241 | $prefix = $slotsTooSmall == XC_TYPE_PHP ? '' : 'var_'; |
---|
[1103] | 242 | result(N_("warning") |
---|
[1092] | 243 | , _T("Slots value too small") |
---|
| 244 | , sprintf(_T("So many item are cached. Increase %s to a more proper value"), "xcache.{$prefix}slots") |
---|
| 245 | ); |
---|
| 246 | } |
---|
| 247 | else { |
---|
[1103] | 248 | result(N_("info"), _T('Looks good')); |
---|
[1092] | 249 | } |
---|
| 250 | // }}} |
---|
| 251 | checking(_T("Cache Status")); // {{{ |
---|
| 252 | if (!$xcacheLoaded) { |
---|
[1103] | 253 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 254 | } |
---|
| 255 | else if ($disabled) { |
---|
[1103] | 256 | result(N_("warning") |
---|
[1092] | 257 | , _T("At least one of the caches is disabled. ") |
---|
| 258 | , _T("Enable the cache.") |
---|
[1103] | 259 | . (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.')) |
---|
[1092] | 260 | . (ini_get("xcache.crash_on_coredump") ? " " . _T("If it was caused by PHP crash/coredump, report to XCache devs") : "") |
---|
| 261 | ); |
---|
| 262 | } |
---|
| 263 | else { |
---|
[1103] | 264 | result(N_("info"), _T('Idle')); |
---|
[1092] | 265 | } |
---|
| 266 | // }}} |
---|
[1089] | 267 | |
---|
[1092] | 268 | checking(_T("Coredump Directory")); // {{{ |
---|
| 269 | if (!$xcacheLoaded) { |
---|
[1103] | 270 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 271 | } |
---|
| 272 | else if (!ini_get("xcache.coredump_directory")) { |
---|
[1103] | 273 | result(N_("info") |
---|
[1092] | 274 | , _T("Not enabled") |
---|
[1103] | 275 | , _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") |
---|
[1092] | 276 | ); |
---|
| 277 | } |
---|
| 278 | else if (ini_get("xcache.coredump_directory")) { |
---|
| 279 | $coreDir = ini_get("xcache.coredump_directory"); |
---|
| 280 | if (substr($coreDir, -1) != DIRECTORY_SEPARATOR) { |
---|
| 281 | $coreDir .= DIRECTORY_SEPARATOR; |
---|
[1090] | 282 | } |
---|
[1092] | 283 | $coreFiles = glob($coreDir . "core*"); |
---|
| 284 | if ($coreFiles) { |
---|
[1103] | 285 | result(N_("error") |
---|
[1092] | 286 | , _T("Core files found:\n") . implode("\n", $coreFiles) |
---|
[1103] | 287 | , _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") |
---|
[1092] | 288 | ); |
---|
| 289 | } |
---|
| 290 | else { |
---|
[1103] | 291 | result(N_("info") |
---|
[1092] | 292 | , _T("Enabled") |
---|
| 293 | , sprintf(_T("You can see core files if PHP crash in %s if PHP crash"), ini_get("xcache.coredump_directory")) |
---|
| 294 | ); |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | // }}} |
---|
| 298 | checking(_T("Readonly Protection")); // {{{ |
---|
| 299 | if (!$xcacheLoaded) { |
---|
[1103] | 300 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 301 | } |
---|
[1093] | 302 | else if (ini_get("xcache.readonly_protection") && !$readonlyProtection) { |
---|
[1103] | 303 | result(N_("error") |
---|
[1092] | 304 | , _T("Set to enabled but not available") |
---|
| 305 | , _T("Use xcache.mmap_path other than /dev/zero") |
---|
| 306 | ); |
---|
| 307 | } |
---|
| 308 | else { |
---|
[1103] | 309 | result(N_("info") |
---|
[1092] | 310 | , $readonlyProtection ? _T("Enabled") : _T("Disabled") |
---|
| 311 | , _T("Enable readonly_protection == --performance & ++stability. " |
---|
| 312 | . "Disable readonly_protection == ++performance & --stability") |
---|
| 313 | ); |
---|
| 314 | } |
---|
| 315 | // }}} |
---|
| 316 | checking(_T("XCache modules")); // {{{ |
---|
| 317 | if (!$xcacheLoaded) { |
---|
[1103] | 318 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 319 | } |
---|
| 320 | else { |
---|
| 321 | $xcacheModules = explode(" ", XCACHE_MODULES); |
---|
| 322 | $unexpectedModules = array_intersect($xcacheModules, array("coverager", "disassembler")); |
---|
| 323 | if ($unexpectedModules) { |
---|
[1103] | 324 | result(N_("warning") |
---|
[1092] | 325 | , implode("\n", $unexpectedModules) |
---|
[1103] | 326 | , _T("Acceptable. Module(s) listed are built into XCache but not for production server.\n" |
---|
[1092] | 327 | . "Leave it as is if you're feeling good.\n" |
---|
[1103] | 328 | . "Re-configure XCache with the module(s) disabled if you're strict with server security.") |
---|
[1089] | 329 | ); |
---|
| 330 | } |
---|
[1090] | 331 | else { |
---|
[1103] | 332 | result(N_("info"), _T('Idle')); |
---|
[1090] | 333 | } |
---|
[1092] | 334 | } |
---|
| 335 | // }}} |
---|
| 336 | checking(_T("XCache test setting")); // {{{ |
---|
| 337 | if (!$xcacheLoaded) { |
---|
[1103] | 338 | result(N_("skipped"), "XCache not loaded"); |
---|
[1092] | 339 | } |
---|
| 340 | else if ((int) ini_get('xcache.test') == 1) { |
---|
[1103] | 341 | result(N_("warning") |
---|
[1092] | 342 | , _T("Enabled") |
---|
| 343 | , _T("xcache.test is for testing only, not for server. set it to off") |
---|
| 344 | ); |
---|
| 345 | } |
---|
| 346 | else { |
---|
[1103] | 347 | result(N_("info"), _T('Disabled')); |
---|
[1092] | 348 | } |
---|
| 349 | // }}} |
---|
| 350 | checking(_T("PHP Version")); // {{{ |
---|
| 351 | $phpVersion = phpversion(); |
---|
| 352 | $unstablePhpVersionReason = null; |
---|
| 353 | foreach ($knownUnstablePhpVersions as $knownUnstablePhpVersion) { |
---|
| 354 | list($compareOp, $unstablePhpVersion, $reason) = $knownUnstablePhpVersion; |
---|
| 355 | if ($compareOp) { |
---|
| 356 | $isUnstable = version_compare($phpVersion, $unstablePhpVersion, $compareOp); |
---|
[1090] | 357 | } |
---|
[1092] | 358 | else { |
---|
| 359 | $isUnstable = substr($phpVersion, 0, strlen($unstablePhpVersion)) == $unstablePhpVersion; |
---|
[1090] | 360 | } |
---|
[1089] | 361 | |
---|
[1092] | 362 | if ($isUnstable) { |
---|
| 363 | $unstablePhpVersionReason = $reason; |
---|
| 364 | break; |
---|
[1090] | 365 | } |
---|
[1089] | 366 | } |
---|
[1092] | 367 | if ($unstablePhpVersionReason) { |
---|
[1103] | 368 | result(N_("error") |
---|
[1092] | 369 | , _T("The version of PHP you're using is known to be unstable: ") . $unstablePhpVersionReason |
---|
| 370 | , _T("Upgrade to new version of PHP")); |
---|
[1089] | 371 | } |
---|
[1092] | 372 | else { |
---|
[1103] | 373 | result(N_("info"), _T("Looks good")); |
---|
[1089] | 374 | } |
---|
[1092] | 375 | // }}} |
---|
| 376 | checking(_T("Extension Compatibility")); // {{{ |
---|
| 377 | $loadedZendExtensions = get_loaded_extensions(true); |
---|
| 378 | if (array_search("Zend Optimizer", $loadedZendExtensions) !== false) { |
---|
[1103] | 379 | result(N_("info") |
---|
[1092] | 380 | , _T("Zend Optimizer loaded") |
---|
| 381 | , _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") |
---|
| 382 | ); |
---|
[1089] | 383 | } |
---|
[1103] | 384 | else { |
---|
| 385 | result(N_("info"), _T("Looks good")); |
---|
| 386 | } |
---|
[1092] | 387 | // }}} |
---|
[1125] | 388 | checking(_T("SAPI Compatibility")); // {{{ |
---|
[1089] | 389 | |
---|
[1125] | 390 | if (php_sapi_name() == "cgi" || php_sapi_name() == "cgi-fcgi" && !isset($_SERVER["FCGI_ROLE"])) { |
---|
| 391 | result(N_("error"), _T("CGI is not supported"), _T("Use FastCGI or FPM instead")); |
---|
| 392 | } |
---|
| 393 | else if (php_sapi_name() == "cgi-fcgi" && isset($_SERVER["FCGI_ROLE"]) && (int) getenv("PHP_FCGI_CHILDREN") < 1) { |
---|
| 394 | result(N_("error") |
---|
| 395 | , "PHP_FCGI_CHILDREN<1" |
---|
| 396 | , _T("PHP_FCGI_CHILDREN should be >= 1 and use 1 group of parent/childs model. See http://xcache.lighttpd.net/wiki/Faq")); |
---|
| 397 | } |
---|
| 398 | else { |
---|
| 399 | result(N_("info"), _T("Looks good")); |
---|
| 400 | } |
---|
| 401 | // }}} |
---|
| 402 | |
---|
[1089] | 403 | include "./diagnosis.tpl.php"; |
---|
| 404 | |
---|