Changeset 1092


Ignore:
Timestamp:
2012-07-31T11:22:10+02:00 (2 years ago)
Author:
moo
Message:

diagnosis: impl checks

Location:
trunk/htdocs/diagnosis
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/diagnosis/diagnosis.tpl.php

    r1090 r1092  
    11<?php include "../common/header.tpl.php"; ?> 
    2 <table cellspacing="0" cellpadding="4" class="cycles"> 
     2<table cellspacing="0" cellpadding="4" class="cycles" id="diagnosisResult"> 
    33    <caption> 
    44        <?php echo _T("Diagnosis Result"); ?> 
     
    66    <tr> 
    77        <th> 
     8            <?php echo _T("Item"); ?> 
     9        </th> 
     10        <th> 
    811            <?php echo _T("Level"); ?> 
    912        </th> 
    1013        <th> 
    11             <?php echo _T("Reason"); ?> 
     14            <?php echo _T("Result"); ?> 
    1215        </th> 
    1316        <th> 
    14             <?php echo _T("Suggestion"); ?> 
     17            <?php echo _T("Result/Suggestion"); ?> 
    1518        </th> 
    1619    </tr> 
    1720<?php foreach ($notes as $note) { ?> 
    18     <tr> 
    19         <td><?php echo ucfirst($note['type']); ?></td> 
    20         <td><?php echo $note['reason']; ?></td> 
    21         <td><?php echo $note['suggestion']; ?></td> 
     21    <tr class="<?php echo $note['type']; ?>"> 
     22        <td nowrap="nowrap" align="right"><?php echo $note['item']; ?></td> 
     23        <td nowrap="nowrap"><?php echo ucfirst($note['type']); ?></td> 
     24        <td nowrap="nowrap"><?php echo nl2br($note['result']); ?></td> 
     25        <td><?php echo nl2br($note['suggestion']); ?></td> 
    2226    </tr> 
    2327<?php } ?> 
  • trunk/htdocs/diagnosis/index.php

    r1090 r1092  
    22 
    33include "../common/common.php"; 
     4$knownUnstablePhpVersions = array( 
     5        array('=', '5.3.14', 'random corrupt memory on high concurrent'), 
     6        ); 
    47 
    58$module = "diagnosis"; 
    69 
    710$notes = array(); 
    8 function note($type, $reason, $suggestion = "ok") // {{{ 
     11$activeNote = null; 
     12function checking($item) // {{{ 
    913{ 
    10     global $notes; 
     14    global $activeNote; 
     15    $activeNote = array('item' => $item); 
     16} 
     17// }}} 
     18function result($type, $result, $suggestion = "") // {{{ 
     19{ 
     20    global $notes, $activeNote; 
    1121    $notes[] = array( 
    1222            'type' => $type 
    13             , 'reason' => $reason 
     23            , 'result' => ($type != 'skipped' && !$suggestion ? "OK. " : "") . $result 
    1424            , 'suggestion' => $suggestion 
    15             ); 
     25            ) + $activeNote; 
    1626} 
    1727// }}} 
     
    3646} 
    3747// }}} 
    38  
    39 if (!extension_loaded('XCache')) { 
     48function getIniFileInfo() // {{{ 
     49{ 
    4050    ob_start(); 
    4151    phpinfo(INFO_GENERAL); 
     
    4353    ob_start(); 
    4454    if (preg_match_all("!<tr>[^<]*<td[^>]*>[^<]*(?:Configuration|ini|Server API)[^<]*</td>[^<]*<td[^>]*>[^<]*</td>[^<]*</tr>!s", $info, $m)) { 
    45         echo '<div class="phpinfo">'; 
    46         echo 'PHP Info'; 
    47         echo '<table>'; 
    48         echo implode('', $m[0]); 
    49         echo '</table>'; 
    50         echo '</div>'; 
    51     } 
     55        $iniInfo = '<table class="phpinfo">' 
     56            . implode('', $m[0]) 
     57            . '</table>'; 
     58    } 
     59    else { 
     60        $iniInfo = ''; 
     61    } 
     62    $loadedIni = ''; 
     63    $iniDirectory = ''; 
    5264    if (preg_match('!<td class="v">(.*?\\.ini)!', $info, $m)) { 
    53         echo "Please check $m[1]"; 
     65        $loadedIni = $m[1]; 
    5466    } 
    5567    else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) { 
    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'); 
     75checking(_T("XCache extension")); // {{{ 
     76if (!$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} 
     90else { 
     91    result("info", _T('Loaded')); 
     92} 
     93// }}} 
     94if ($xcacheLoaded) { // {{{ load XCache summary 
    6795    $cacheInfos = getCacheInfos(); 
    6896 
    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// }}} 
     122checking(_T("Enabling PHP Cacher")); // {{{ 
     123if (!$xcacheLoaded) { 
     124    result("skipped", "XCache not loaded"); 
     125} 
     126else 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} 
     133else 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} 
     140else { 
     141    result("info", _T('Enabled')); 
     142} 
     143// }}} 
     144checking(_T("PHP Compile Time Error")); // {{{ 
     145if (!$xcacheLoaded) { 
     146    result("skipped", "XCache not loaded"); 
     147} 
     148else if (!$phpCacheCount) { 
     149    result("skipped", "XCache PHP cacher not enabled"); 
     150} 
     151else 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} 
     158else { 
     159    result("info", _T('No error happened')); 
     160} 
     161// }}} 
     162checking(_T("Busy Compiling")); // {{{ 
     163if (!$xcacheLoaded) { 
     164    result("skipped", "XCache not loaded"); 
     165} 
     166else if (!$phpCacheCount) { 
     167    result("skipped", "XCache PHP cacher not enabled"); 
     168} 
     169else 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} 
     176else { 
     177    result("info", _T('Idle')); 
     178} 
     179// }}} 
     180checking(_T("Enabling VAR Cacher")); // {{{ 
     181if (!$xcacheLoaded) { 
     182    result("skipped", "XCache not loaded"); 
     183} 
     184else 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} 
     191else { 
     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") 
    74201            ); 
    75202    } 
    76203    else { 
    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// }}} 
     209checking(_T("Cache Size")); // {{{ 
     210if (!$xcacheLoaded) { 
     211    result("skipped", "XCache not loaded"); 
     212} 
     213else 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} 
     220else { 
     221    result("info", _T('Enough')); 
     222} 
     223// }}} 
     224checking(_T("Slots")); // {{{ 
     225$slotsTooBig = null; 
     226$slotsTooSmall = null; 
     227foreach ($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} 
     237if (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} 
     246else 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} 
     254else { 
     255    result("info", _T('Looks good')); 
     256} 
     257// }}} 
     258checking(_T("Cache Status")); // {{{ 
     259if (!$xcacheLoaded) { 
     260    result("skipped", "XCache not loaded"); 
     261} 
     262else 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} 
     271else { 
     272    result("info", _T('Idle')); 
     273} 
     274// }}} 
     275 
     276checking(_T("Coredump Directory")); // {{{ 
     277if (!$xcacheLoaded) { 
     278    result("skipped", "XCache not loaded"); 
     279} 
     280else 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} 
     286else 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// }}} 
     306checking(_T("Readonly Protection")); // {{{ 
     307if (!$xcacheLoaded) { 
     308    result("skipped", "XCache not loaded"); 
     309} 
     310else 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} 
     317else { 
     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// }}} 
     326checking(_T("XCache modules")); // {{{ 
     327if (!$xcacheLoaded) { 
     328    result("skipped", "XCache not loaded"); 
     329} 
     330else { 
     331    $xcacheModules = explode(" ", XCACHE_MODULES); 
     332    $unexpectedModules = array_intersect($xcacheModules, array("coverager", "disassembler")); 
     333    if ($unexpectedModules) { 
     334        result( 
    89335            "warning" 
    90             , _T("Out of memory happened when trying to write to cache") 
    91             , "Increase xcache.size and/or xcache.var_size" 
     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.") 
    92340            ); 
    93341    } 
    94342    else { 
    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// }}} 
     347checking(_T("XCache test setting")); // {{{ 
     348if (!$xcacheLoaded) { 
     349    result("skipped", "XCache not loaded"); 
     350} 
     351else 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} 
     358else { 
     359    result("info", _T('Disabled')); 
     360} 
     361// }}} 
     362checking(_T("PHP Version")); // {{{ 
     363$phpVersion = phpversion(); 
     364$unstablePhpVersionReason = null; 
     365foreach ($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} 
     379if ($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} 
     384else { 
     385    result("info", _T("Looks good")); 
     386} 
     387// }}} 
     388checking(_T("Extension Compatibility")); // {{{ 
     389$loadedZendExtensions = get_loaded_extensions(true); 
     390if (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// }}} 
    157398 
    158399include "./diagnosis.tpl.php"; 
Note: See TracChangeset for help on using the changeset viewer.