From b0291af8d99fe2718986af175d09bb5d21dc300c Mon Sep 17 00:00:00 2001 From: Xuefer Date: Mon, 30 Jul 2012 15:01:09 +0000 Subject: [PATCH] diagnosis: impl some advises git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1090 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- htdocs/cacher/index.php | 25 +----- htdocs/common/common.php | 2 +- htdocs/diagnosis/diagnosis.tpl.php | 23 ++++++ htdocs/diagnosis/index.php | 118 +++++++++++++++++++++-------- 4 files changed, 112 insertions(+), 56 deletions(-) diff --git a/htdocs/cacher/index.php b/htdocs/cacher/index.php index bfe9b15..3c7ce6e 100644 --- a/htdocs/cacher/index.php +++ b/htdocs/cacher/index.php @@ -256,30 +256,7 @@ function getEntryList() // {{{ $module = "cacher"; xcache_count(XC_TYPE_PHP); // trigger auth if (!extension_loaded('XCache')) { - include "../common/header.tpl.php"; - echo '

XCache is not loaded

'; - ob_start(); - phpinfo(INFO_GENERAL); - $info = ob_get_clean(); - if (preg_match_all("![^<]*]*>[^<]*(?:Configuration|ini|Server API)[^<]*[^<]*]*>[^<]*[^<]*!s", $info, $m)) { - echo '
'; - echo 'PHP Info'; - echo ''; - echo implode('', $m[0]); - echo '
'; - echo '
'; - } - if (preg_match('!(.*?\\.ini)!', $info, $m)) { - echo "Please check $m[1]"; - } - else if (preg_match('!Configuration File \\(php.ini\\) Path *([^<]+)!', $info, $m)) { - echo "Please put a php.ini in $m[1] and load XCache extension"; - } - else { - echo "You don't even have a php.ini yet?"; - } - echo "(See above)"; - include "../common/footer.tpl.php"; + header("Location: ../diagnosis"); exit; } diff --git a/htdocs/common/common.php b/htdocs/common/common.php index b716970..5dbb16f 100644 --- a/htdocs/common/common.php +++ b/htdocs/common/common.php @@ -148,7 +148,7 @@ function _T($str) return $GLOBALS['strings'][$str]; } if (!empty($GLOBALS['config']['show_todo_strings'])) { - return '' . htmlspecialchars($str) . '|'; + return '' . $str . '|'; } return $str; } diff --git a/htdocs/diagnosis/diagnosis.tpl.php b/htdocs/diagnosis/diagnosis.tpl.php index 84fd3d0..479bc8e 100644 --- a/htdocs/diagnosis/diagnosis.tpl.php +++ b/htdocs/diagnosis/diagnosis.tpl.php @@ -1,2 +1,25 @@ + + + + + + + + + + + + + + +
+ +
+ + + + + +
diff --git a/htdocs/diagnosis/index.php b/htdocs/diagnosis/index.php index a9c399a..0db6a28 100644 --- a/htdocs/diagnosis/index.php +++ b/htdocs/diagnosis/index.php @@ -5,7 +5,7 @@ include "../common/common.php"; $module = "diagnosis"; $notes = array(); -function note($type, $reason, $suggestion) +function note($type, $reason, $suggestion = "ok") // {{{ { global $notes; $notes[] = array( @@ -14,7 +14,7 @@ function note($type, $reason, $suggestion) , 'suggestion' => $suggestion ); } - +// }}} function getCacheInfos() // {{{ { $phpCacheCount = xcache_count(XC_TYPE_PHP); @@ -34,51 +34,107 @@ function getCacheInfos() // {{{ } return $cacheInfos; } +// }}} -$cacheInfos = getCacheInfos(); +if (!extension_loaded('XCache')) { + ob_start(); + phpinfo(INFO_GENERAL); + $info = ob_get_clean(); + ob_start(); + if (preg_match_all("![^<]*]*>[^<]*(?:Configuration|ini|Server API)[^<]*[^<]*]*>[^<]*[^<]*!s", $info, $m)) { + echo '
'; + echo 'PHP Info'; + echo ''; + echo implode('', $m[0]); + echo '
'; + echo '
'; + } + if (preg_match('!(.*?\\.ini)!', $info, $m)) { + echo "Please check $m[1]"; + } + else if (preg_match('!Configuration File \\(php.ini\\) Path *([^<]+)!', $info, $m)) { + echo "Please put a php.ini in $m[1] and load XCache extension"; + } + else { + echo "You don't even have a php.ini yet?"; + } + echo "(See above)"; + note("error", _T('XCache is not loaded'), ob_get_clean()); +} +else { + note("info", _T('XCache loaded')); -// if (!$ini['xcache.size'] || !$ini['xcache.cacher']) { + $cacheInfos = getCacheInfos(); -foreach ($cacheInfos as $cacheInfo) { - if ($cacheInfo['ooms']) { + if (!ini_get("xcache.size") || !ini_get("xcache.cacher")) { + note( + "error" + , _T("XCache is not enabled. Website is not accelerated by XCache") + , _T("Set xcache.size to non-zero, set xcache.cacher = On") + ); + } + else { + note("info", _T('XCache Enabled')); + } + + $ooms = false; + foreach ($cacheInfos as $cacheInfo) { + if ($cacheInfo['ooms']) { + $ooms = true; + break; + } + } + if ($ooms) { note( "warning" - , "Out of memory happened when trying to write to cache" + , _T("Out of memory happened when trying to write to cache") , "Increase xcache.size and/or xcache.var_size" ); - break; } -} + else { + note("info", _T('XCache Memory Size')); + } -foreach ($cacheInfos as $cacheInfo) { - if ($cacheInfo['errors']) { + $errors = false; + foreach ($cacheInfos as $cacheInfo) { + if ($cacheInfo['errors']) { + $errors = true; + break; + } + } + if ($errors) { note( "warning" - , "Error happened when compiling your PHP code" - , "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" + , _T("Error happened when compiling at least one of your PHP code") + , _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") ); - break; } + else { + note("info", _T('All PHP scripts seem fine')); + } + + /* + if ($ini['xcache.count'] < cpucount() * 2) { + } + + if ($ini['xcache.size'] is small $ini['xcache.slots'] is big) { + } + + if ($ini['xcache.readonly_protection']) { + } + + if ($cache['compiling']) { + } + + if ($cache['compiling']) { + } + + if ($cache['disabled']) { + } + */ } /* -if ($ini['xcache.count'] < cpucount() * 2) { -} - -if ($ini['xcache.size'] is small $ini['xcache.slots'] is big) { -} - -if ($ini['xcache.readonly_protection']) { -} - -if ($cache['compiling']) { -} - -if ($cache['compiling']) { -} - -if ($cache['disabled']) { -} if (($coredumpFiles = globCoreDumpFiles()) { }