| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | include "../common/common.php"; |
|---|
| 4 | include 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; |
|---|
| 14 | function checking($item) // {{{ |
|---|
| 15 | { |
|---|
| 16 | global $activeNote; |
|---|
| 17 | $activeNote = array('item' => $item); |
|---|
| 18 | } |
|---|
| 19 | // }}} |
|---|
| 20 | function 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 | // }}} |
|---|
| 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 | } |
|---|
| 49 | // }}} |
|---|
| 50 | function 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'); |
|---|
| 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 | } |
|---|
| 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 | } |
|---|
| 92 | else { |
|---|
| 93 | result(N_("info"), _T('Loaded')); |
|---|
| 94 | } |
|---|
| 95 | // }}} |
|---|
| 96 | if ($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 | // }}} |
|---|
| 124 | checking(_T("Enabling PHP Cacher")); // {{{ |
|---|
| 125 | if (!$xcacheLoaded) { |
|---|
| 126 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 127 | } |
|---|
| 128 | else 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 | } |
|---|
| 134 | else 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 | } |
|---|
| 140 | else { |
|---|
| 141 | result(N_("info"), _T('Enabled')); |
|---|
| 142 | } |
|---|
| 143 | // }}} |
|---|
| 144 | checking(_T("PHP Compile Time Error")); // {{{ |
|---|
| 145 | if (!$xcacheLoaded) { |
|---|
| 146 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 147 | } |
|---|
| 148 | else if (!$phpCacheCount) { |
|---|
| 149 | result(N_("skipped"), "XCache PHP cacher not enabled"); |
|---|
| 150 | } |
|---|
| 151 | else if ($errors) { |
|---|
| 152 | result(N_("warning") |
|---|
| 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 { |
|---|
| 158 | result(N_("info"), _T('No error happened')); |
|---|
| 159 | } |
|---|
| 160 | // }}} |
|---|
| 161 | checking(_T("Busy Compiling")); // {{{ |
|---|
| 162 | if (!$xcacheLoaded) { |
|---|
| 163 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 164 | } |
|---|
| 165 | else if (!$phpCacheCount) { |
|---|
| 166 | result(N_("skipped"), "XCache PHP cacher not enabled"); |
|---|
| 167 | } |
|---|
| 168 | else 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 | } |
|---|
| 174 | else { |
|---|
| 175 | result(N_("info"), _T('Idle')); |
|---|
| 176 | } |
|---|
| 177 | // }}} |
|---|
| 178 | checking(_T("Enabling VAR Cacher")); // {{{ |
|---|
| 179 | if (!$xcacheLoaded) { |
|---|
| 180 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 181 | } |
|---|
| 182 | else if (!ini_get("xcache.var_size")) { |
|---|
| 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") |
|---|
| 186 | ); |
|---|
| 187 | } |
|---|
| 188 | else { |
|---|
| 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 | // }}} |
|---|
| 205 | checking(_T("Cache Size")); // {{{ |
|---|
| 206 | if (!$xcacheLoaded) { |
|---|
| 207 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 208 | } |
|---|
| 209 | else 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 | } |
|---|
| 215 | else { |
|---|
| 216 | result(N_("info"), _T('Enough')); |
|---|
| 217 | } |
|---|
| 218 | // }}} |
|---|
| 219 | checking(_T("Hash Slots")); // {{{ |
|---|
| 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_'; |
|---|
| 234 | result(N_("warning") |
|---|
| 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_'; |
|---|
| 242 | result(N_("warning") |
|---|
| 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 { |
|---|
| 248 | result(N_("info"), _T('Looks good')); |
|---|
| 249 | } |
|---|
| 250 | // }}} |
|---|
| 251 | checking(_T("Cache Status")); // {{{ |
|---|
| 252 | if (!$xcacheLoaded) { |
|---|
| 253 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 254 | } |
|---|
| 255 | else if ($disabled) { |
|---|
| 256 | result(N_("warning") |
|---|
| 257 | , _T("At least one of the caches is disabled. ") |
|---|
| 258 | , _T("Enable the cache.") |
|---|
| 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.')) |
|---|
| 260 | . (ini_get("xcache.crash_on_coredump") ? " " . _T("If it was caused by PHP crash/coredump, report to XCache devs") : "") |
|---|
| 261 | ); |
|---|
| 262 | } |
|---|
| 263 | else { |
|---|
| 264 | result(N_("info"), _T('Idle')); |
|---|
| 265 | } |
|---|
| 266 | // }}} |
|---|
| 267 | |
|---|
| 268 | checking(_T("Coredump Directory")); // {{{ |
|---|
| 269 | if (!$xcacheLoaded) { |
|---|
| 270 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 271 | } |
|---|
| 272 | else if (!ini_get("xcache.coredump_directory")) { |
|---|
| 273 | result(N_("info") |
|---|
| 274 | , _T("Not enabled") |
|---|
| 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") |
|---|
| 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; |
|---|
| 282 | } |
|---|
| 283 | $coreFiles = glob($coreDir . "core*"); |
|---|
| 284 | if ($coreFiles) { |
|---|
| 285 | result(N_("error") |
|---|
| 286 | , _T("Core files found:\n") . implode("\n", $coreFiles) |
|---|
| 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") |
|---|
| 288 | ); |
|---|
| 289 | } |
|---|
| 290 | else { |
|---|
| 291 | result(N_("info") |
|---|
| 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) { |
|---|
| 300 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 301 | } |
|---|
| 302 | else if (ini_get("xcache.readonly_protection") && !$readonlyProtection) { |
|---|
| 303 | result(N_("error") |
|---|
| 304 | , _T("Set to enabled but not available") |
|---|
| 305 | , _T("Use xcache.mmap_path other than /dev/zero") |
|---|
| 306 | ); |
|---|
| 307 | } |
|---|
| 308 | else { |
|---|
| 309 | result(N_("info") |
|---|
| 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) { |
|---|
| 318 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 319 | } |
|---|
| 320 | else { |
|---|
| 321 | $xcacheModules = explode(" ", XCACHE_MODULES); |
|---|
| 322 | $unexpectedModules = array_intersect($xcacheModules, array("coverager", "disassembler")); |
|---|
| 323 | if ($unexpectedModules) { |
|---|
| 324 | result(N_("warning") |
|---|
| 325 | , implode("\n", $unexpectedModules) |
|---|
| 326 | , _T("Acceptable. Module(s) listed are built into XCache but not for production server.\n" |
|---|
| 327 | . "Leave it as is if you're feeling good.\n" |
|---|
| 328 | . "Re-configure XCache with the module(s) disabled if you're strict with server security.") |
|---|
| 329 | ); |
|---|
| 330 | } |
|---|
| 331 | else { |
|---|
| 332 | result(N_("info"), _T('Idle')); |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | // }}} |
|---|
| 336 | checking(_T("XCache test setting")); // {{{ |
|---|
| 337 | if (!$xcacheLoaded) { |
|---|
| 338 | result(N_("skipped"), "XCache not loaded"); |
|---|
| 339 | } |
|---|
| 340 | else if ((int) ini_get('xcache.test') == 1) { |
|---|
| 341 | result(N_("warning") |
|---|
| 342 | , _T("Enabled") |
|---|
| 343 | , _T("xcache.test is for testing only, not for server. set it to off") |
|---|
| 344 | ); |
|---|
| 345 | } |
|---|
| 346 | else { |
|---|
| 347 | result(N_("info"), _T('Disabled')); |
|---|
| 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); |
|---|
| 357 | } |
|---|
| 358 | else { |
|---|
| 359 | $isUnstable = substr($phpVersion, 0, strlen($unstablePhpVersion)) == $unstablePhpVersion; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | if ($isUnstable) { |
|---|
| 363 | $unstablePhpVersionReason = $reason; |
|---|
| 364 | break; |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | if ($unstablePhpVersionReason) { |
|---|
| 368 | result(N_("error") |
|---|
| 369 | , _T("The version of PHP you're using is known to be unstable: ") . $unstablePhpVersionReason |
|---|
| 370 | , _T("Upgrade to new version of PHP")); |
|---|
| 371 | } |
|---|
| 372 | else { |
|---|
| 373 | result(N_("info"), _T("Looks good")); |
|---|
| 374 | } |
|---|
| 375 | // }}} |
|---|
| 376 | checking(_T("Extension Compatibility")); // {{{ |
|---|
| 377 | $loadedZendExtensions = get_loaded_extensions(true); |
|---|
| 378 | if (array_search("Zend Optimizer", $loadedZendExtensions) !== false) { |
|---|
| 379 | result(N_("info") |
|---|
| 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 | ); |
|---|
| 383 | } |
|---|
| 384 | else { |
|---|
| 385 | result(N_("info"), _T("Looks good")); |
|---|
| 386 | } |
|---|
| 387 | // }}} |
|---|
| 388 | |
|---|
| 389 | include "./diagnosis.tpl.php"; |
|---|
| 390 | |
|---|