| [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); |
|---|
| [1084] | 87 | $a = $active ? ' class="active"' : ''; |
|---|
| 88 | $height = 20 - 1 * 2; |
|---|
| [1068] | 89 | $valueHeight = ceil($height * $percent / 100); |
|---|
| 90 | $paddingHeight = $height - $valueHeight; |
|---|
| 91 | $valueHeight = $valueHeight ? $valueHeight . "px" : 0; |
|---|
| 92 | $paddingHeight = $paddingHeight ? $paddingHeight . "px" : 0; |
|---|
| [1084] | 93 | return '<a title="' . $v . '" href="javascript:;"' . $a . '>' |
|---|
| [1085] | 94 | . ($paddingHeight ? '<span style="height: ' . $paddingHeight . '"></span>' : '') |
|---|
| 95 | . ($valueHeight ? '<span style="background: rgb(' . "$r,$g,$b" . '); height: ' . $valueHeight . '"></span>' : '') |
|---|
| [1084] | 96 | . '</a>'; |
|---|
| [522] | 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; |
|---|
| [1084] | 112 | |
|---|
| [522] | 113 | $html = array(); |
|---|
| [1084] | 114 | $width = count($ci[$key]) * 2; |
|---|
| 115 | $html[] = '<div class="hitsgraph" style="width: ' . $width . 'px">'; |
|---|
| [1058] | 116 | foreach ($ci[$key] as $i => $v) { |
|---|
| [538] | 117 | $html[] = bar_hits_percent($v, $v / $max, $i == $t); |
|---|
| [522] | 118 | } |
|---|
| [1084] | 119 | $html[] = "</div>"; |
|---|
| [522] | 120 | return implode('', $html); |
|---|
| 121 | } |
|---|
| [1078] | 122 | // }}} |
|---|
| 123 | function getModuleInfo() // {{{ |
|---|
| [1074] | 124 | { |
|---|
| 125 | ob_start(); |
|---|
| 126 | phpinfo(INFO_MODULES); |
|---|
| 127 | $moduleInfo = ob_get_clean(); |
|---|
| 128 | if (!preg_match_all('!(XCache[^<>]*)</a></h2>(.*?)<h2>!is', $moduleInfo, $m)) { |
|---|
| 129 | return; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | $moduleInfo = array(); |
|---|
| 133 | foreach ($m[1] as $i => $dummy) { |
|---|
| [1080] | 134 | $caption = trim($m[1][$i]); |
|---|
| 135 | $info = str_replace('<br />', '', trim($m[2][$i])); |
|---|
| 136 | |
|---|
| 137 | $regex = '!<table[^>]*>!'; |
|---|
| 138 | if (preg_match($regex, $info)) { |
|---|
| 139 | $moduleInfo[] = preg_replace($regex, "\\0<caption>$caption</caption>", $info, 1); |
|---|
| 140 | } |
|---|
| 141 | else { |
|---|
| 142 | $moduleInfo[] = "<h3>$caption</h3>"; |
|---|
| 143 | $moduleInfo[] = $info; |
|---|
| 144 | } |
|---|
| [1074] | 145 | } |
|---|
| 146 | return implode('', $moduleInfo); |
|---|
| 147 | } |
|---|
| [1078] | 148 | // }}} |
|---|
| 149 | function getCacheInfos() // {{{ |
|---|
| 150 | { |
|---|
| 151 | static $cacheInfos; |
|---|
| 152 | if (isset($cacheInfos)) { |
|---|
| 153 | return $cacheInfos; |
|---|
| 154 | } |
|---|
| [1074] | 155 | |
|---|
| [1078] | 156 | $phpCacheCount = xcache_count(XC_TYPE_PHP); |
|---|
| 157 | $varCacheCount = xcache_count(XC_TYPE_VAR); |
|---|
| 158 | |
|---|
| 159 | $cacheInfos = array(); |
|---|
| 160 | $total = array(); |
|---|
| 161 | global $maxHitsByHour; |
|---|
| 162 | $maxHitsByHour = array(0, 0); |
|---|
| 163 | for ($i = 0; $i < $phpCacheCount; $i ++) { |
|---|
| 164 | $data = xcache_info(XC_TYPE_PHP, $i); |
|---|
| 165 | if ($_GET['do'] === 'listphp') { |
|---|
| 166 | $data += xcache_list(XC_TYPE_PHP, $i); |
|---|
| 167 | } |
|---|
| 168 | $data['type'] = XC_TYPE_PHP; |
|---|
| 169 | $data['cache_name'] = "php#$i"; |
|---|
| 170 | $data['cacheid'] = $i; |
|---|
| 171 | $cacheInfos[] = $data; |
|---|
| 172 | $maxHitsByHour[XC_TYPE_PHP] = max($maxHitsByHour[XC_TYPE_PHP], max($data['hits_by_hour'])); |
|---|
| 173 | if ($phpCacheCount >= 2) { |
|---|
| 174 | calc_total($total, $data); |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | if ($phpCacheCount >= 2) { |
|---|
| 179 | $total['type'] = XC_TYPE_PHP; |
|---|
| [1086] | 180 | $total['cache_name'] = _T('Total'); |
|---|
| [1078] | 181 | $total['cacheid'] = -1; |
|---|
| 182 | $total['gc'] = null; |
|---|
| 183 | $total['istotal'] = true; |
|---|
| 184 | unset($total['compiling']); |
|---|
| 185 | $cacheInfos[] = $total; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | $total = array(); |
|---|
| 189 | for ($i = 0; $i < $varCacheCount; $i ++) { |
|---|
| 190 | $data = xcache_info(XC_TYPE_VAR, $i); |
|---|
| 191 | if ($_GET['do'] === 'listvar') { |
|---|
| 192 | $data += xcache_list(XC_TYPE_VAR, $i); |
|---|
| 193 | } |
|---|
| 194 | $data['type'] = XC_TYPE_VAR; |
|---|
| 195 | $data['cache_name'] = "var#$i"; |
|---|
| 196 | $data['cacheid'] = $i; |
|---|
| 197 | $cacheInfos[] = $data; |
|---|
| 198 | $maxHitsByHour[XC_TYPE_VAR] = max($maxHitsByHour[XC_TYPE_VAR], max($data['hits_by_hour'])); |
|---|
| 199 | if ($varCacheCount >= 2) { |
|---|
| 200 | calc_total($total, $data); |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | if ($varCacheCount >= 2) { |
|---|
| 205 | $total['type'] = XC_TYPE_VAR; |
|---|
| [1086] | 206 | $total['cache_name'] = _T('Total'); |
|---|
| [1078] | 207 | $total['cacheid'] = -1; |
|---|
| 208 | $total['gc'] = null; |
|---|
| 209 | $total['istotal'] = true; |
|---|
| 210 | $cacheInfos[] = $total; |
|---|
| 211 | } |
|---|
| 212 | return $cacheInfos; |
|---|
| 213 | } |
|---|
| 214 | // }}} |
|---|
| 215 | function getEntryList() // {{{ |
|---|
| 216 | { |
|---|
| 217 | static $entryList; |
|---|
| 218 | if (isset($entryList)) { |
|---|
| 219 | return $entryList; |
|---|
| 220 | } |
|---|
| 221 | $entryList = array('cache_list' => array(), 'deleted_list' => array()); |
|---|
| 222 | if ($_GET['do'] == 'listphp') { |
|---|
| 223 | $entryList['type_name'] = 'php'; |
|---|
| 224 | $entryList['type'] = XC_TYPE_PHP; |
|---|
| 225 | } |
|---|
| 226 | else { |
|---|
| 227 | $entryList['type_name'] = 'var'; |
|---|
| 228 | $entryList['type'] = XC_TYPE_VAR; |
|---|
| 229 | } |
|---|
| 230 | foreach (getCacheInfos() as $i => $c) { |
|---|
| 231 | if (!empty($c['istotal'])) { |
|---|
| 232 | continue; |
|---|
| 233 | } |
|---|
| 234 | if ($c['type'] == $entryList['type'] && isset($c['cache_list'])) { |
|---|
| 235 | foreach ($c['cache_list'] as $e) { |
|---|
| 236 | $e['cache_name'] = $c['cache_name']; |
|---|
| 237 | $entryList['cache_list'][] = $e; |
|---|
| 238 | } |
|---|
| 239 | foreach ($c['deleted_list'] as $e) { |
|---|
| 240 | $e['cache_name'] = $c['cache_name']; |
|---|
| 241 | $entryList['deleted_list'][] = $e; |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | return $entryList; |
|---|
| 246 | } |
|---|
| 247 | // }}} |
|---|
| 248 | |
|---|
| [1053] | 249 | $module = "cacher"; |
|---|
| [1081] | 250 | xcache_count(XC_TYPE_PHP); // trigger auth |
|---|
| [133] | 251 | if (!extension_loaded('XCache')) { |
|---|
| [1078] | 252 | include "../common/header.tpl.php"; |
|---|
| [133] | 253 | echo '<h1>XCache is not loaded</h1>'; |
|---|
| 254 | ob_start(); |
|---|
| [1041] | 255 | phpinfo(INFO_GENERAL); |
|---|
| [133] | 256 | $info = ob_get_clean(); |
|---|
| [1041] | 257 | if (preg_match_all("!<tr>[^<]*<td[^>]*>[^<]*(?:Configuration|ini|Server API)[^<]*</td>[^<]*<td[^>]*>[^<]*</td>[^<]*</tr>!s", $info, $m)) { |
|---|
| 258 | echo '<div class="phpinfo">'; |
|---|
| 259 | echo 'PHP Info'; |
|---|
| 260 | echo '<table>'; |
|---|
| 261 | echo implode('', $m[0]); |
|---|
| 262 | echo '</table>'; |
|---|
| 263 | echo '</div>'; |
|---|
| 264 | } |
|---|
| 265 | if (preg_match('!<td class="v">(.*?\\.ini)!', $info, $m)) { |
|---|
| [133] | 266 | echo "Please check $m[1]"; |
|---|
| 267 | } |
|---|
| [421] | 268 | else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) { |
|---|
| 269 | echo "Please put a php.ini in $m[1] and load XCache extension"; |
|---|
| 270 | } |
|---|
| [133] | 271 | else { |
|---|
| [142] | 272 | echo "You don't even have a php.ini yet?"; |
|---|
| [133] | 273 | } |
|---|
| [1041] | 274 | echo "(See above)"; |
|---|
| [1078] | 275 | include "../common/footer.tpl.php"; |
|---|
| [133] | 276 | exit; |
|---|
| 277 | } |
|---|
| [34] | 278 | |
|---|
| [1078] | 279 | $doTypes = array( |
|---|
| [1086] | 280 | '' => _T('Summary'), |
|---|
| 281 | 'listphp' => _T('List PHP'), |
|---|
| 282 | 'listvar' => _T('List Var Data'), |
|---|
| 283 | 'help' => _T('Help'), |
|---|
| [1078] | 284 | ); |
|---|
| 285 | |
|---|
| 286 | function processPOST() // {{{ |
|---|
| 287 | { |
|---|
| 288 | if (isset($_POST['remove']) && is_array($_POST['remove'])) { |
|---|
| 289 | foreach ($_POST['remove'] as $name) { |
|---|
| 290 | if (is_string($name)) { |
|---|
| 291 | xcache_unset($name); |
|---|
| 292 | } |
|---|
| [371] | 293 | } |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| [34] | 296 | $type = isset($_POST['type']) ? $_POST['type'] : null; |
|---|
| 297 | if ($type != XC_TYPE_PHP && $type != XC_TYPE_VAR) { |
|---|
| 298 | $type = null; |
|---|
| 299 | } |
|---|
| 300 | if (isset($type)) { |
|---|
| 301 | $cacheid = (int) (isset($_POST['cacheid']) ? $_POST['cacheid'] : 0); |
|---|
| 302 | if (isset($_POST['clearcache'])) { |
|---|
| [1064] | 303 | xcache_clear_cache($type, $cacheid); |
|---|
| [34] | 304 | } |
|---|
| [1064] | 305 | if (isset($_POST['enable'])) { |
|---|
| 306 | xcache_enable_cache($type, $cacheid); |
|---|
| 307 | } |
|---|
| 308 | if (isset($_POST['disable'])) { |
|---|
| 309 | xcache_enable_cache($type, $cacheid, false); |
|---|
| 310 | } |
|---|
| [34] | 311 | } |
|---|
| [1078] | 312 | |
|---|
| 313 | if (isset($_POST['coredump'])) { |
|---|
| 314 | xcache_coredump(); |
|---|
| 315 | } |
|---|
| [34] | 316 | } |
|---|
| 317 | // }}} |
|---|
| [521] | 318 | |
|---|
| [1078] | 319 | processPOST(); |
|---|
| [521] | 320 | |
|---|
| [1078] | 321 | if (!isset($_GET['do'])) { |
|---|
| 322 | $_GET['do'] = ''; |
|---|
| [34] | 323 | } |
|---|
| [521] | 324 | |
|---|
| [1074] | 325 | switch ($_GET['do']) { |
|---|
| 326 | case 'listphp': |
|---|
| 327 | case 'listvar': |
|---|
| [1078] | 328 | include "./listentries.tpl.php"; |
|---|
| [34] | 329 | break; |
|---|
| 330 | |
|---|
| [1078] | 331 | case 'help': |
|---|
| 332 | include "./help.tpl.php"; |
|---|
| 333 | break; |
|---|
| 334 | |
|---|
| [34] | 335 | default: |
|---|
| [1078] | 336 | include "./summary.tpl.php"; |
|---|
| 337 | break; |
|---|
| [34] | 338 | } |
|---|
| 339 | |
|---|
| 340 | ?> |
|---|