| [34] | 1 | <?php |
|---|
| 2 | |
|---|
| [1078] | 3 | include "./common.php"; |
|---|
| [34] | 4 | |
|---|
| [1078] | 5 | function freeblock_to_graph($freeblocks, $size) // {{{ |
|---|
| [517] | 6 | { |
|---|
| [902] | 7 | global $config; |
|---|
| [517] | 8 | |
|---|
| 9 | // cached in static variable |
|---|
| 10 | static $graph_initial; |
|---|
| 11 | if (!isset($graph_initial)) { |
|---|
| [902] | 12 | $graph_initial = array_fill(0, $config['percent_graph_width'], 0); |
|---|
| [517] | 13 | } |
|---|
| 14 | $graph = $graph_initial; |
|---|
| 15 | foreach ($freeblocks as $b) { |
|---|
| [902] | 16 | $begin = $b['offset'] / $size * $config['percent_graph_width']; |
|---|
| 17 | $end = ($b['offset'] + $b['size']) / $size * $config['percent_graph_width']; |
|---|
| [517] | 18 | |
|---|
| [520] | 19 | if ((int) $begin == (int) $end) { |
|---|
| 20 | $v = $end - $begin; |
|---|
| 21 | $graph[(int) $v] += $v - (int) $v; |
|---|
| [517] | 22 | } |
|---|
| [520] | 23 | else { |
|---|
| 24 | $graph[(int) $begin] += 1 - ($begin - (int) $begin); |
|---|
| 25 | $graph[(int) $end] += $end - (int) $end; |
|---|
| 26 | for ($i = (int) $begin + 1, $e = (int) $end; $i < $e; $i ++) { |
|---|
| 27 | $graph[$i] += 1; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| [517] | 30 | } |
|---|
| 31 | $html = array(); |
|---|
| 32 | $c = 255; |
|---|
| 33 | foreach ($graph as $k => $v) { |
|---|
| [902] | 34 | if ($config['percent_graph_type'] != 'free') { |
|---|
| [526] | 35 | $v = 1 - $v; |
|---|
| 36 | } |
|---|
| [517] | 37 | $v = (int) ($v * $c); |
|---|
| 38 | $r = $g = $c - $v; |
|---|
| 39 | $b = $c; |
|---|
| 40 | $html[] = '<div style="background: rgb(' . "$r,$g,$b" . ')"></div>'; |
|---|
| 41 | } |
|---|
| 42 | return implode('', $html); |
|---|
| 43 | } |
|---|
| [1078] | 44 | // }}} |
|---|
| 45 | function calc_total(&$total, $data) // {{{ |
|---|
| [522] | 46 | { |
|---|
| 47 | foreach ($data as $k => $v) { |
|---|
| 48 | switch ($k) { |
|---|
| 49 | case 'type': |
|---|
| 50 | case 'cache_name': |
|---|
| 51 | case 'cacheid': |
|---|
| 52 | case 'free_blocks': |
|---|
| 53 | continue 2; |
|---|
| 54 | } |
|---|
| 55 | if (!isset($total[$k])) { |
|---|
| 56 | $total[$k] = $v; |
|---|
| 57 | } |
|---|
| 58 | else { |
|---|
| 59 | switch ($k) { |
|---|
| [552] | 60 | case 'hits_by_hour': |
|---|
| 61 | case 'hits_by_second': |
|---|
| [522] | 62 | foreach ($data[$k] as $kk => $vv) { |
|---|
| 63 | $total[$k][$kk] += $vv; |
|---|
| 64 | } |
|---|
| 65 | break; |
|---|
| 66 | |
|---|
| 67 | default: |
|---|
| 68 | $total[$k] += $v; |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| [1078] | 73 | // }}} |
|---|
| 74 | function array_avg($a) // {{{ |
|---|
| [522] | 75 | { |
|---|
| 76 | if (count($a) == 0) { |
|---|
| 77 | return ''; |
|---|
| 78 | } |
|---|
| 79 | return array_sum($a) / count($a); |
|---|
| 80 | } |
|---|
| [1078] | 81 | // }}} |
|---|
| 82 | function bar_hits_percent($v, $percent, $active) // {{{ |
|---|
| [522] | 83 | { |
|---|
| 84 | $r = 220 + (int) ($percent * 25); |
|---|
| 85 | $g = $b = 220 - (int) ($percent * 220); |
|---|
| 86 | $percent = (int) ($percent * 100); |
|---|
| [535] | 87 | $a = $active ? ' active' : ''; |
|---|
| [1068] | 88 | $height = 20; |
|---|
| 89 | $valueHeight = ceil($height * $percent / 100); |
|---|
| 90 | $paddingHeight = $height - $valueHeight; |
|---|
| 91 | $valueHeight = $valueHeight ? $valueHeight . "px" : 0; |
|---|
| 92 | $paddingHeight = $paddingHeight ? $paddingHeight . "px" : 0; |
|---|
| [538] | 93 | return '<div title="' . $v . '">' |
|---|
| [1068] | 94 | . '<div class="barf' . $a . '" style="height: ' . $paddingHeight . '"></div>' |
|---|
| 95 | . '<div class="barv' . $a . '" style="background: rgb(' . "$r,$g,$b" . '); height: ' . $valueHeight . '"></div>' |
|---|
| [522] | 96 | . '</div>'; |
|---|
| 97 | } |
|---|
| [1078] | 98 | // }}} |
|---|
| 99 | function get_cache_hits_graph($ci, $key) // {{{ |
|---|
| [522] | 100 | { |
|---|
| [1078] | 101 | global $maxHitsByHour; |
|---|
| [1058] | 102 | if ($ci['cacheid'] == -1) { |
|---|
| 103 | $max = max($ci[$key]); |
|---|
| [522] | 104 | } |
|---|
| [1058] | 105 | else { |
|---|
| [1078] | 106 | $max = $maxHitsByHour[$ci['type']]; |
|---|
| [1058] | 107 | } |
|---|
| [522] | 108 | if (!$max) { |
|---|
| [1058] | 109 | $max = 1; |
|---|
| [522] | 110 | } |
|---|
| [535] | 111 | $t = (time() / (60 * 60)) % 24; |
|---|
| [522] | 112 | $html = array(); |
|---|
| [1058] | 113 | foreach ($ci[$key] as $i => $v) { |
|---|
| [538] | 114 | $html[] = bar_hits_percent($v, $v / $max, $i == $t); |
|---|
| [522] | 115 | } |
|---|
| 116 | return implode('', $html); |
|---|
| 117 | } |
|---|
| [1078] | 118 | // }}} |
|---|
| 119 | function getModuleInfo() // {{{ |
|---|
| [1074] | 120 | { |
|---|
| 121 | ob_start(); |
|---|
| 122 | phpinfo(INFO_MODULES); |
|---|
| 123 | $moduleInfo = ob_get_clean(); |
|---|
| 124 | if (!preg_match_all('!(XCache[^<>]*)</a></h2>(.*?)<h2>!is', $moduleInfo, $m)) { |
|---|
| 125 | return; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | $moduleInfo = array(); |
|---|
| 129 | foreach ($m[1] as $i => $dummy) { |
|---|
| [1080] | 130 | $caption = trim($m[1][$i]); |
|---|
| 131 | $info = str_replace('<br />', '', trim($m[2][$i])); |
|---|
| 132 | |
|---|
| 133 | $regex = '!<table[^>]*>!'; |
|---|
| 134 | if (preg_match($regex, $info)) { |
|---|
| 135 | $moduleInfo[] = preg_replace($regex, "\\0<caption>$caption</caption>", $info, 1); |
|---|
| 136 | } |
|---|
| 137 | else { |
|---|
| 138 | $moduleInfo[] = "<h3>$caption</h3>"; |
|---|
| 139 | $moduleInfo[] = $info; |
|---|
| 140 | } |
|---|
| [1074] | 141 | } |
|---|
| 142 | return implode('', $moduleInfo); |
|---|
| 143 | } |
|---|
| [1078] | 144 | // }}} |
|---|
| 145 | function getCacheInfos() // {{{ |
|---|
| 146 | { |
|---|
| 147 | static $cacheInfos; |
|---|
| 148 | if (isset($cacheInfos)) { |
|---|
| 149 | return $cacheInfos; |
|---|
| 150 | } |
|---|
| [1074] | 151 | |
|---|
| [1078] | 152 | $phpCacheCount = xcache_count(XC_TYPE_PHP); |
|---|
| 153 | $varCacheCount = xcache_count(XC_TYPE_VAR); |
|---|
| 154 | |
|---|
| 155 | $cacheInfos = array(); |
|---|
| 156 | $total = array(); |
|---|
| 157 | global $maxHitsByHour; |
|---|
| 158 | $maxHitsByHour = array(0, 0); |
|---|
| 159 | for ($i = 0; $i < $phpCacheCount; $i ++) { |
|---|
| 160 | $data = xcache_info(XC_TYPE_PHP, $i); |
|---|
| 161 | if ($_GET['do'] === 'listphp') { |
|---|
| 162 | $data += xcache_list(XC_TYPE_PHP, $i); |
|---|
| 163 | } |
|---|
| 164 | $data['type'] = XC_TYPE_PHP; |
|---|
| 165 | $data['cache_name'] = "php#$i"; |
|---|
| 166 | $data['cacheid'] = $i; |
|---|
| 167 | $cacheInfos[] = $data; |
|---|
| 168 | $maxHitsByHour[XC_TYPE_PHP] = max($maxHitsByHour[XC_TYPE_PHP], max($data['hits_by_hour'])); |
|---|
| 169 | if ($phpCacheCount >= 2) { |
|---|
| 170 | calc_total($total, $data); |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | if ($phpCacheCount >= 2) { |
|---|
| 175 | $total['type'] = XC_TYPE_PHP; |
|---|
| 176 | $total['cache_name'] = _('Total'); |
|---|
| 177 | $total['cacheid'] = -1; |
|---|
| 178 | $total['gc'] = null; |
|---|
| 179 | $total['istotal'] = true; |
|---|
| 180 | unset($total['compiling']); |
|---|
| 181 | $cacheInfos[] = $total; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | $total = array(); |
|---|
| 185 | for ($i = 0; $i < $varCacheCount; $i ++) { |
|---|
| 186 | $data = xcache_info(XC_TYPE_VAR, $i); |
|---|
| 187 | if ($_GET['do'] === 'listvar') { |
|---|
| 188 | $data += xcache_list(XC_TYPE_VAR, $i); |
|---|
| 189 | } |
|---|
| 190 | $data['type'] = XC_TYPE_VAR; |
|---|
| 191 | $data['cache_name'] = "var#$i"; |
|---|
| 192 | $data['cacheid'] = $i; |
|---|
| 193 | $cacheInfos[] = $data; |
|---|
| 194 | $maxHitsByHour[XC_TYPE_VAR] = max($maxHitsByHour[XC_TYPE_VAR], max($data['hits_by_hour'])); |
|---|
| 195 | if ($varCacheCount >= 2) { |
|---|
| 196 | calc_total($total, $data); |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | if ($varCacheCount >= 2) { |
|---|
| 201 | $total['type'] = XC_TYPE_VAR; |
|---|
| 202 | $total['cache_name'] = _('Total'); |
|---|
| 203 | $total['cacheid'] = -1; |
|---|
| 204 | $total['gc'] = null; |
|---|
| 205 | $total['istotal'] = true; |
|---|
| 206 | $cacheInfos[] = $total; |
|---|
| 207 | } |
|---|
| 208 | return $cacheInfos; |
|---|
| 209 | } |
|---|
| 210 | // }}} |
|---|
| 211 | function getEntryList() // {{{ |
|---|
| 212 | { |
|---|
| 213 | static $entryList; |
|---|
| 214 | if (isset($entryList)) { |
|---|
| 215 | return $entryList; |
|---|
| 216 | } |
|---|
| 217 | $entryList = array('cache_list' => array(), 'deleted_list' => array()); |
|---|
| 218 | if ($_GET['do'] == 'listphp') { |
|---|
| 219 | $entryList['type_name'] = 'php'; |
|---|
| 220 | $entryList['type'] = XC_TYPE_PHP; |
|---|
| 221 | } |
|---|
| 222 | else { |
|---|
| 223 | $entryList['type_name'] = 'var'; |
|---|
| 224 | $entryList['type'] = XC_TYPE_VAR; |
|---|
| 225 | } |
|---|
| 226 | foreach (getCacheInfos() as $i => $c) { |
|---|
| 227 | if (!empty($c['istotal'])) { |
|---|
| 228 | continue; |
|---|
| 229 | } |
|---|
| 230 | if ($c['type'] == $entryList['type'] && isset($c['cache_list'])) { |
|---|
| 231 | foreach ($c['cache_list'] as $e) { |
|---|
| 232 | $e['cache_name'] = $c['cache_name']; |
|---|
| 233 | $entryList['cache_list'][] = $e; |
|---|
| 234 | } |
|---|
| 235 | foreach ($c['deleted_list'] as $e) { |
|---|
| 236 | $e['cache_name'] = $c['cache_name']; |
|---|
| 237 | $entryList['deleted_list'][] = $e; |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | return $entryList; |
|---|
| 242 | } |
|---|
| 243 | // }}} |
|---|
| 244 | |
|---|
| [1053] | 245 | $module = "cacher"; |
|---|
| [1081] | 246 | xcache_count(XC_TYPE_PHP); // trigger auth |
|---|
| [133] | 247 | if (!extension_loaded('XCache')) { |
|---|
| [1078] | 248 | include "../common/header.tpl.php"; |
|---|
| [133] | 249 | echo '<h1>XCache is not loaded</h1>'; |
|---|
| 250 | ob_start(); |
|---|
| [1041] | 251 | phpinfo(INFO_GENERAL); |
|---|
| [133] | 252 | $info = ob_get_clean(); |
|---|
| [1041] | 253 | if (preg_match_all("!<tr>[^<]*<td[^>]*>[^<]*(?:Configuration|ini|Server API)[^<]*</td>[^<]*<td[^>]*>[^<]*</td>[^<]*</tr>!s", $info, $m)) { |
|---|
| 254 | echo '<div class="phpinfo">'; |
|---|
| 255 | echo 'PHP Info'; |
|---|
| 256 | echo '<table>'; |
|---|
| 257 | echo implode('', $m[0]); |
|---|
| 258 | echo '</table>'; |
|---|
| 259 | echo '</div>'; |
|---|
| 260 | } |
|---|
| 261 | if (preg_match('!<td class="v">(.*?\\.ini)!', $info, $m)) { |
|---|
| [133] | 262 | echo "Please check $m[1]"; |
|---|
| 263 | } |
|---|
| [421] | 264 | else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) { |
|---|
| 265 | echo "Please put a php.ini in $m[1] and load XCache extension"; |
|---|
| 266 | } |
|---|
| [133] | 267 | else { |
|---|
| [142] | 268 | echo "You don't even have a php.ini yet?"; |
|---|
| [133] | 269 | } |
|---|
| [1041] | 270 | echo "(See above)"; |
|---|
| [1078] | 271 | include "../common/footer.tpl.php"; |
|---|
| [133] | 272 | exit; |
|---|
| 273 | } |
|---|
| [34] | 274 | |
|---|
| [1078] | 275 | $doTypes = array( |
|---|
| 276 | '' => _('Summary'), |
|---|
| 277 | 'listphp' => _('List PHP'), |
|---|
| 278 | 'listvar' => _('List Var Data'), |
|---|
| 279 | 'help' => _('Help'), |
|---|
| 280 | ); |
|---|
| 281 | |
|---|
| 282 | function processPOST() // {{{ |
|---|
| 283 | { |
|---|
| 284 | if (isset($_POST['remove']) && is_array($_POST['remove'])) { |
|---|
| 285 | foreach ($_POST['remove'] as $name) { |
|---|
| 286 | if (is_string($name)) { |
|---|
| 287 | xcache_unset($name); |
|---|
| 288 | } |
|---|
| [371] | 289 | } |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| [34] | 292 | $type = isset($_POST['type']) ? $_POST['type'] : null; |
|---|
| 293 | if ($type != XC_TYPE_PHP && $type != XC_TYPE_VAR) { |
|---|
| 294 | $type = null; |
|---|
| 295 | } |
|---|
| 296 | if (isset($type)) { |
|---|
| 297 | $cacheid = (int) (isset($_POST['cacheid']) ? $_POST['cacheid'] : 0); |
|---|
| 298 | if (isset($_POST['clearcache'])) { |
|---|
| [1064] | 299 | xcache_clear_cache($type, $cacheid); |
|---|
| [34] | 300 | } |
|---|
| [1064] | 301 | if (isset($_POST['enable'])) { |
|---|
| 302 | xcache_enable_cache($type, $cacheid); |
|---|
| 303 | } |
|---|
| 304 | if (isset($_POST['disable'])) { |
|---|
| 305 | xcache_enable_cache($type, $cacheid, false); |
|---|
| 306 | } |
|---|
| [34] | 307 | } |
|---|
| [1078] | 308 | |
|---|
| 309 | if (isset($_POST['coredump'])) { |
|---|
| 310 | xcache_coredump(); |
|---|
| 311 | } |
|---|
| [34] | 312 | } |
|---|
| 313 | // }}} |
|---|
| [521] | 314 | |
|---|
| [1078] | 315 | processPOST(); |
|---|
| [521] | 316 | |
|---|
| [1078] | 317 | if (!isset($_GET['do'])) { |
|---|
| 318 | $_GET['do'] = ''; |
|---|
| [34] | 319 | } |
|---|
| [521] | 320 | |
|---|
| [1074] | 321 | switch ($_GET['do']) { |
|---|
| 322 | case 'listphp': |
|---|
| 323 | case 'listvar': |
|---|
| [1078] | 324 | include "./listentries.tpl.php"; |
|---|
| [34] | 325 | break; |
|---|
| 326 | |
|---|
| [1078] | 327 | case 'help': |
|---|
| 328 | include "./help.tpl.php"; |
|---|
| 329 | break; |
|---|
| 330 | |
|---|
| [34] | 331 | default: |
|---|
| [1078] | 332 | include "./summary.tpl.php"; |
|---|
| 333 | break; |
|---|
| [34] | 334 | } |
|---|
| 335 | |
|---|
| 336 | ?> |
|---|