| 56 | | echo "Please put a php.ini in $m[1] and load XCache extension"; |
| 57 | | } |
| 58 | | else { |
| 59 | | echo "You don't even have a php.ini yet?"; |
| 60 | | } |
| 61 | | echo "(See above)"; |
| 62 | | note("error", _T('XCache is not loaded'), ob_get_clean()); |
| 63 | | } |
| 64 | | else { |
| 65 | | note("info", _T('XCache loaded')); |
| 66 | | |
| | 68 | $iniDirectory = $m[1]; |
| | 69 | } |
| | 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 | } |
| | 84 | else { |
| | 85 | echo _T("Cannot detect ini location"); |
| | 86 | } |
| | 87 | echo _T(" (See above)"); |
| | 88 | result("error", _T('Not loaded'), ob_get_clean()); |
| | 89 | } |
| | 90 | else { |
| | 91 | result("info", _T('Loaded')); |
| | 92 | } |
| | 93 | // }}} |
| | 94 | if ($xcacheLoaded) { // {{{ load XCache summary |
| 69 | | if (!ini_get("xcache.size") || !ini_get("xcache.cacher")) { |
| 70 | | note( |
| 71 | | "error" |
| 72 | | , _T("XCache is not enabled. Website is not accelerated by XCache") |
| 73 | | , _T("Set xcache.size to non-zero, set xcache.cacher = On") |
| | 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; |
| | 105 | foreach ($cacheInfos as $cacheInfo) { |
| | 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']; |
| | 112 | } |
| | 113 | if ($cacheInfo['type'] == XC_TYPE_VAR && $cacheInfo['cached']) { |
| | 114 | $varCached += $cacheInfo['cached']; |
| | 115 | } |
| | 116 | if ($cacheInfo['can_readonly']) { |
| | 117 | $readonlyProtection = true; |
| | 118 | } |
| | 119 | } |
| | 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( |
| | 197 | "warning" |
| | 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") |
| 77 | | note("info", _T('XCache Enabled')); |
| 78 | | } |
| 79 | | |
| 80 | | $ooms = false; |
| 81 | | foreach ($cacheInfos as $cacheInfo) { |
| 82 | | if ($cacheInfo['ooms']) { |
| 83 | | $ooms = true; |
| 84 | | break; |
| 85 | | } |
| 86 | | } |
| 87 | | if ($ooms) { |
| 88 | | note( |
| | 204 | result("info", _T('Cache in use')); |
| | 205 | } |
| | 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 | // }}} |
| | 275 | |
| | 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; |
| | 290 | } |
| | 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( |
| 95 | | note("info", _T('XCache Memory Size')); |
| 96 | | } |
| 97 | | |
| 98 | | $errors = false; |
| 99 | | foreach ($cacheInfos as $cacheInfo) { |
| 100 | | if ($cacheInfo['errors']) { |
| 101 | | $errors = true; |
| 102 | | break; |
| 103 | | } |
| 104 | | } |
| 105 | | if ($errors) { |
| 106 | | note( |
| 107 | | "warning" |
| 108 | | , _T("Error happened when compiling at least one of your PHP code") |
| 109 | | , _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") |
| 110 | | ); |
| 111 | | } |
| 112 | | else { |
| 113 | | note("info", _T('All PHP scripts seem fine')); |
| 114 | | } |
| 115 | | |
| 116 | | /* |
| 117 | | if ($ini['xcache.count'] < cpucount() * 2) { |
| 118 | | } |
| 119 | | |
| 120 | | if ($ini['xcache.size'] is small $ini['xcache.slots'] is big) { |
| 121 | | } |
| 122 | | |
| 123 | | if ($ini['xcache.readonly_protection']) { |
| 124 | | } |
| 125 | | |
| 126 | | if ($cache['compiling']) { |
| 127 | | } |
| 128 | | |
| 129 | | if ($cache['compiling']) { |
| 130 | | } |
| 131 | | |
| 132 | | if ($cache['disabled']) { |
| 133 | | } |
| 134 | | */ |
| 135 | | } |
| 136 | | |
| 137 | | /* |
| 138 | | |
| 139 | | if (($coredumpFiles = globCoreDumpFiles()) { |
| 140 | | } |
| 141 | | |
| 142 | | if (module not for server) { |
| 143 | | } |
| 144 | | |
| 145 | | $phpVersion = php_version(); |
| 146 | | foreach ($knownUnstablePhpVersion as $unstablePhpVersion => $reason) { |
| 147 | | if (substr($phpVersion, 0, strlen($unstablePhpVersion)) == $unstablePhpVersion) { |
| 148 | | // .. |
| 149 | | } |
| 150 | | } |
| 151 | | |
| 152 | | if (Zend Optimizer is loaded, zend optimize level > 0) { |
| 153 | | warn("disabled"); |
| 154 | | } |
| 155 | | |
| 156 | | */ |
| | 343 | result("info", _T('Idle')); |
| | 344 | } |
| | 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); |
| | 369 | } |
| | 370 | else { |
| | 371 | $isUnstable = substr($phpVersion, 0, strlen($unstablePhpVersion)) == $unstablePhpVersion; |
| | 372 | } |
| | 373 | |
| | 374 | if ($isUnstable) { |
| | 375 | $unstablePhpVersionReason = $reason; |
| | 376 | break; |
| | 377 | } |
| | 378 | } |
| | 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")); |
| | 383 | } |
| | 384 | else { |
| | 385 | result("info", _T("Looks good")); |
| | 386 | } |
| | 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 | ); |
| | 396 | } |
| | 397 | // }}} |