| [34] | 1 | <?php |
|---|
| 2 | |
|---|
| [123] | 3 | include("./common.php"); |
|---|
| [34] | 4 | |
|---|
| [517] | 5 | function freeblock_to_graph($freeblocks, $size) |
|---|
| 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 | } |
|---|
| 44 | |
|---|
| [522] | 45 | function calc_total(&$total, $data) |
|---|
| 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 | } |
|---|
| 73 | |
|---|
| 74 | function array_avg($a) |
|---|
| 75 | { |
|---|
| 76 | if (count($a) == 0) { |
|---|
| 77 | return ''; |
|---|
| 78 | } |
|---|
| 79 | return array_sum($a) / count($a); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| [538] | 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' : ''; |
|---|
| [538] | 88 | return '<div title="' . $v . '">' |
|---|
| [535] | 89 | . '<div class="barf' . $a . '" style="height: ' . (100 - $percent) . '%"></div>' |
|---|
| 90 | . '<div class="barv' . $a . '" style="background: rgb(' . "$r,$g,$b" . '); height: ' . $percent . '%"></div>' |
|---|
| [522] | 91 | . '</div>'; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| [1058] | 94 | function get_cache_hits_graph($ci, $key) |
|---|
| [522] | 95 | { |
|---|
| [1058] | 96 | if ($ci['cacheid'] == -1) { |
|---|
| 97 | $max = max($ci[$key]); |
|---|
| [522] | 98 | } |
|---|
| [1058] | 99 | else { |
|---|
| 100 | $max = $GLOBALS['maxhits_by_hour'][$ci['type']]; |
|---|
| 101 | } |
|---|
| [522] | 102 | if (!$max) { |
|---|
| [1058] | 103 | $max = 1; |
|---|
| [522] | 104 | } |
|---|
| [535] | 105 | $t = (time() / (60 * 60)) % 24; |
|---|
| [522] | 106 | $html = array(); |
|---|
| [1058] | 107 | foreach ($ci[$key] as $i => $v) { |
|---|
| [538] | 108 | $html[] = bar_hits_percent($v, $v / $max, $i == $t); |
|---|
| [522] | 109 | } |
|---|
| 110 | return implode('', $html); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| [1053] | 113 | $module = "cacher"; |
|---|
| [133] | 114 | if (!extension_loaded('XCache')) { |
|---|
| [1053] | 115 | include("../common/header.tpl.php"); |
|---|
| [133] | 116 | echo '<h1>XCache is not loaded</h1>'; |
|---|
| 117 | ob_start(); |
|---|
| [1041] | 118 | phpinfo(INFO_GENERAL); |
|---|
| [133] | 119 | $info = ob_get_clean(); |
|---|
| [1041] | 120 | if (preg_match_all("!<tr>[^<]*<td[^>]*>[^<]*(?:Configuration|ini|Server API)[^<]*</td>[^<]*<td[^>]*>[^<]*</td>[^<]*</tr>!s", $info, $m)) { |
|---|
| 121 | echo '<div class="phpinfo">'; |
|---|
| 122 | echo 'PHP Info'; |
|---|
| 123 | echo '<table>'; |
|---|
| 124 | echo implode('', $m[0]); |
|---|
| 125 | echo '</table>'; |
|---|
| 126 | echo '</div>'; |
|---|
| 127 | } |
|---|
| 128 | if (preg_match('!<td class="v">(.*?\\.ini)!', $info, $m)) { |
|---|
| [133] | 129 | echo "Please check $m[1]"; |
|---|
| 130 | } |
|---|
| [421] | 131 | else if (preg_match('!Configuration File \\(php.ini\\) Path *</td><td class="v">([^<]+)!', $info, $m)) { |
|---|
| 132 | echo "Please put a php.ini in $m[1] and load XCache extension"; |
|---|
| 133 | } |
|---|
| [133] | 134 | else { |
|---|
| [142] | 135 | echo "You don't even have a php.ini yet?"; |
|---|
| [133] | 136 | } |
|---|
| [1041] | 137 | echo "(See above)"; |
|---|
| [1053] | 138 | include("../common/footer.tpl.php"); |
|---|
| [133] | 139 | exit; |
|---|
| 140 | } |
|---|
| [34] | 141 | $pcnt = xcache_count(XC_TYPE_PHP); |
|---|
| 142 | $vcnt = xcache_count(XC_TYPE_VAR); |
|---|
| 143 | |
|---|
| [371] | 144 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|---|
| 145 | $remove = @ $_POST['remove']; |
|---|
| 146 | if ($remove && is_array($remove)) { |
|---|
| 147 | foreach ($remove as $name) { |
|---|
| 148 | xcache_unset($name); |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| [147] | 153 | $moduleinfo = null; |
|---|
| [34] | 154 | $type_none = -1; |
|---|
| 155 | if (!isset($_GET['type'])) { |
|---|
| 156 | $_GET['type'] = $type_none; |
|---|
| 157 | } |
|---|
| 158 | $_GET['type'] = $type = (int) $_GET['type']; |
|---|
| 159 | |
|---|
| [1064] | 160 | // {{{ process clear, enable, disable |
|---|
| 161 | function processAction() |
|---|
| [34] | 162 | { |
|---|
| 163 | $type = isset($_POST['type']) ? $_POST['type'] : null; |
|---|
| 164 | if ($type != XC_TYPE_PHP && $type != XC_TYPE_VAR) { |
|---|
| 165 | $type = null; |
|---|
| 166 | } |
|---|
| 167 | if (isset($type)) { |
|---|
| 168 | $cacheid = (int) (isset($_POST['cacheid']) ? $_POST['cacheid'] : 0); |
|---|
| 169 | if (isset($_POST['clearcache'])) { |
|---|
| [1064] | 170 | xcache_clear_cache($type, $cacheid); |
|---|
| [34] | 171 | } |
|---|
| [1064] | 172 | if (isset($_POST['enable'])) { |
|---|
| 173 | xcache_enable_cache($type, $cacheid); |
|---|
| 174 | } |
|---|
| 175 | if (isset($_POST['disable'])) { |
|---|
| 176 | xcache_enable_cache($type, $cacheid, false); |
|---|
| 177 | } |
|---|
| [34] | 178 | } |
|---|
| 179 | } |
|---|
| [1064] | 180 | processAction(); |
|---|
| [1066] | 181 | if (isset($_POST['coredump'])) { |
|---|
| 182 | xcache_coredump(); |
|---|
| 183 | } |
|---|
| [34] | 184 | // }}} |
|---|
| 185 | // {{{ load info/list |
|---|
| 186 | $cacheinfos = array(); |
|---|
| [521] | 187 | $total = array(); |
|---|
| [1058] | 188 | $maxhits_by_hour = array(0, 0); |
|---|
| [34] | 189 | for ($i = 0; $i < $pcnt; $i ++) { |
|---|
| 190 | $data = xcache_info(XC_TYPE_PHP, $i); |
|---|
| 191 | if ($type === XC_TYPE_PHP) { |
|---|
| 192 | $data += xcache_list(XC_TYPE_PHP, $i); |
|---|
| 193 | } |
|---|
| 194 | $data['type'] = XC_TYPE_PHP; |
|---|
| 195 | $data['cache_name'] = "php#$i"; |
|---|
| 196 | $data['cacheid'] = $i; |
|---|
| 197 | $cacheinfos[] = $data; |
|---|
| [1058] | 198 | $maxhits_by_hour[XC_TYPE_PHP] = max($maxhits_by_hour[XC_TYPE_PHP], max($data['hits_by_hour'])); |
|---|
| [521] | 199 | if ($pcnt >= 2) { |
|---|
| [522] | 200 | calc_total($total, $data); |
|---|
| [521] | 201 | } |
|---|
| [34] | 202 | } |
|---|
| [521] | 203 | |
|---|
| 204 | if ($pcnt >= 2) { |
|---|
| 205 | $total['type'] = XC_TYPE_PHP; |
|---|
| [1038] | 206 | $total['cache_name'] = _('Total'); |
|---|
| [976] | 207 | $total['cacheid'] = -1; |
|---|
| [521] | 208 | $total['gc'] = null; |
|---|
| 209 | $total['istotal'] = true; |
|---|
| [1064] | 210 | unset($total['compiling']); |
|---|
| [521] | 211 | $cacheinfos[] = $total; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | $total = array(); |
|---|
| [34] | 215 | for ($i = 0; $i < $vcnt; $i ++) { |
|---|
| 216 | $data = xcache_info(XC_TYPE_VAR, $i); |
|---|
| 217 | if ($type === XC_TYPE_VAR) { |
|---|
| 218 | $data += xcache_list(XC_TYPE_VAR, $i); |
|---|
| 219 | } |
|---|
| 220 | $data['type'] = XC_TYPE_VAR; |
|---|
| 221 | $data['cache_name'] = "var#$i"; |
|---|
| 222 | $data['cacheid'] = $i; |
|---|
| 223 | $cacheinfos[] = $data; |
|---|
| [1058] | 224 | $maxhits_by_hour[XC_TYPE_VAR] = max($maxhits_by_hour[XC_TYPE_VAR], max($data['hits_by_hour'])); |
|---|
| [704] | 225 | if ($vcnt >= 2) { |
|---|
| [522] | 226 | calc_total($total, $data); |
|---|
| [521] | 227 | } |
|---|
| [34] | 228 | } |
|---|
| [521] | 229 | |
|---|
| 230 | if ($vcnt >= 2) { |
|---|
| 231 | $total['type'] = XC_TYPE_VAR; |
|---|
| [1038] | 232 | $total['cache_name'] = _('Total'); |
|---|
| [976] | 233 | $total['cacheid'] = -1; |
|---|
| [521] | 234 | $total['gc'] = null; |
|---|
| 235 | $total['istotal'] = true; |
|---|
| 236 | $cacheinfos[] = $total; |
|---|
| 237 | } |
|---|
| [34] | 238 | // }}} |
|---|
| 239 | // {{{ merge the list |
|---|
| 240 | switch ($type) { |
|---|
| 241 | case XC_TYPE_PHP: |
|---|
| 242 | case XC_TYPE_VAR: |
|---|
| 243 | $cachelist = array('type' => $type, 'cache_list' => array(), 'deleted_list' => array()); |
|---|
| 244 | if ($type == XC_TYPE_VAR) { |
|---|
| 245 | $cachelist['type_name'] = 'var'; |
|---|
| 246 | } |
|---|
| 247 | else { |
|---|
| 248 | $cachelist['type_name'] = 'php'; |
|---|
| 249 | } |
|---|
| 250 | foreach ($cacheinfos as $i => $c) { |
|---|
| [521] | 251 | if (!empty($c['istotal'])) { |
|---|
| 252 | continue; |
|---|
| 253 | } |
|---|
| [34] | 254 | if ($c['type'] == $type && isset($c['cache_list'])) { |
|---|
| 255 | foreach ($c['cache_list'] as $e) { |
|---|
| 256 | $e['cache_name'] = $c['cache_name']; |
|---|
| 257 | $cachelist['cache_list'][] = $e; |
|---|
| 258 | } |
|---|
| 259 | foreach ($c['deleted_list'] as $e) { |
|---|
| 260 | $e['cache_name'] = $c['cache_name']; |
|---|
| 261 | $cachelist['deleted_list'][] = $e; |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | } |
|---|
| 265 | if ($type == XC_TYPE_PHP) { |
|---|
| 266 | $inodes = array(); |
|---|
| [84] | 267 | $haveinode = false; |
|---|
| [34] | 268 | foreach ($cachelist['cache_list'] as $e) { |
|---|
| [868] | 269 | if (isset($e['file_inode'])) { |
|---|
| [114] | 270 | $haveinode = true; |
|---|
| [868] | 271 | break; |
|---|
| [84] | 272 | } |
|---|
| [114] | 273 | } |
|---|
| 274 | if (!$haveinode) { |
|---|
| 275 | foreach ($cachelist['deleted_list'] as $e) { |
|---|
| [868] | 276 | if (isset($e['file_inode'])) { |
|---|
| [114] | 277 | $haveinode = true; |
|---|
| [868] | 278 | break; |
|---|
| [114] | 279 | } |
|---|
| [34] | 280 | } |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | unset($data); |
|---|
| 284 | break; |
|---|
| 285 | |
|---|
| 286 | default: |
|---|
| 287 | $_GET['type'] = $type_none; |
|---|
| 288 | $cachelist = array(); |
|---|
| [147] | 289 | ob_start(); |
|---|
| 290 | phpinfo(INFO_MODULES); |
|---|
| 291 | $moduleinfo = ob_get_clean(); |
|---|
| [1041] | 292 | if (preg_match_all('!(XCache[^<>]*)</a></h2>(.*?)<h2>!is', $moduleinfo, $m)) { |
|---|
| 293 | $moduleinfo = array(); |
|---|
| 294 | foreach ($m[1] as $i => $dummy) { |
|---|
| 295 | $moduleinfo[] = '<h3>' . trim($m[1][$i]) . '</h3>'; |
|---|
| 296 | $moduleinfo[] = str_replace('<br />', '', trim($m[2][$i])); |
|---|
| 297 | } |
|---|
| 298 | $moduleinfo = implode('', $moduleinfo); |
|---|
| [147] | 299 | } |
|---|
| 300 | else { |
|---|
| 301 | $moduleinfo = null; |
|---|
| 302 | } |
|---|
| [34] | 303 | break; |
|---|
| 304 | } |
|---|
| 305 | // }}} |
|---|
| 306 | |
|---|
| 307 | $type_php = XC_TYPE_PHP; |
|---|
| 308 | $type_var = XC_TYPE_VAR; |
|---|
| [1053] | 309 | $listTypes = array($type_none => _('Statistics'), $type_php => _('List PHP'), $type_var => _('List Var Data')); |
|---|
| [34] | 310 | |
|---|
| [1053] | 311 | include("cacher.tpl.php"); |
|---|
| [34] | 312 | |
|---|
| 313 | ?> |
|---|