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