| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | error_reporting(E_ALL); |
|---|
| 4 | define('REQUEST_TIME', time()); |
|---|
| 5 | |
|---|
| 6 | class Cycle |
|---|
| 7 | { |
|---|
| 8 | var $values; |
|---|
| 9 | var $i; |
|---|
| 10 | var $count; |
|---|
| 11 | |
|---|
| 12 | function Cycle($v) |
|---|
| 13 | { |
|---|
| 14 | $this->values = func_get_args(); |
|---|
| 15 | $this->i = -1; |
|---|
| 16 | $this->count = count($this->values); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | function next() |
|---|
| 20 | { |
|---|
| 21 | $this->i = ($this->i + 1) % $this->count; |
|---|
| 22 | return $this->values[$this->i]; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | function cur() |
|---|
| 26 | { |
|---|
| 27 | return $this->values[$this->i]; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | function reset() |
|---|
| 31 | { |
|---|
| 32 | $this->i = -1; |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | function number_formats($a, $keys) |
|---|
| 37 | { |
|---|
| 38 | foreach ($keys as $k) { |
|---|
| 39 | $a[$k] = number_format($a[$k]); |
|---|
| 40 | } |
|---|
| 41 | return $a; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | function size($size, $suffix = '', $precision = 2) |
|---|
| 45 | { |
|---|
| 46 | $size = (int) $size; |
|---|
| 47 | if ($size < 1024) |
|---|
| 48 | return number_format($size, $precision) . ' ' . $suffix; |
|---|
| 49 | |
|---|
| 50 | if ($size < 1048576) |
|---|
| 51 | return number_format($size / 1024, $precision) . ' K' . $suffix; |
|---|
| 52 | |
|---|
| 53 | return number_format($size / 1048576, $precision) . ' M' . $suffix; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | function age($time) |
|---|
| 57 | { |
|---|
| 58 | if (!$time) return ''; |
|---|
| 59 | $delta = REQUEST_TIME - $time; |
|---|
| 60 | |
|---|
| 61 | if ($delta < 0) { |
|---|
| 62 | $delta = -$delta; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | static $seconds = array(1, 60, 3600, 86400, 604800, 2678400, 31536000); |
|---|
| 66 | static $name = array('sec', 'min', 'hr', 'day', 'week', 'month', 'year'); |
|---|
| 67 | |
|---|
| 68 | for ($i = 6; $i >= 0; $i --) { |
|---|
| 69 | if ($delta >= $seconds[$i]) { |
|---|
| 70 | $ret = (int) ($delta / $seconds[$i]); |
|---|
| 71 | return $ret . ' ' . $name[$i] . ($ret > 1 ? 's' : ''); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | function switcher($name, $options) |
|---|
| 77 | { |
|---|
| 78 | $n = isset($_GET[$name]) ? $_GET[$name] : null; |
|---|
| 79 | $html = array(); |
|---|
| 80 | foreach ($options as $k => $v) { |
|---|
| 81 | $html[] = sprintf('<a href="?%s=%s"%s>%s</a>', $name, $k, $k == $n ? 'class="active"' : '', $v); |
|---|
| 82 | } |
|---|
| 83 | return implode(' ', $html); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | $charset = "UTF-8"; |
|---|
| 87 | |
|---|
| 88 | if (file_exists("config.php")) { |
|---|
| 89 | include("config.php"); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | $pcnt = xcache_count(XC_TYPE_PHP); |
|---|
| 93 | $vcnt = xcache_count(XC_TYPE_VAR); |
|---|
| 94 | |
|---|
| 95 | $type_none = -1; |
|---|
| 96 | if (!isset($_GET['type'])) { |
|---|
| 97 | $_GET['type'] = $type_none; |
|---|
| 98 | } |
|---|
| 99 | $_GET['type'] = $type = (int) $_GET['type']; |
|---|
| 100 | |
|---|
| 101 | // {{{ process clear |
|---|
| 102 | function processClear() |
|---|
| 103 | { |
|---|
| 104 | $type = isset($_POST['type']) ? $_POST['type'] : null; |
|---|
| 105 | if ($type != XC_TYPE_PHP && $type != XC_TYPE_VAR) { |
|---|
| 106 | $type = null; |
|---|
| 107 | } |
|---|
| 108 | if (isset($type)) { |
|---|
| 109 | $cacheid = (int) (isset($_POST['cacheid']) ? $_POST['cacheid'] : 0); |
|---|
| 110 | if (isset($_POST['clearcache'])) { |
|---|
| 111 | xcache_clear_cache($type, $cacheid); |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | processClear(); |
|---|
| 116 | // }}} |
|---|
| 117 | // {{{ load info/list |
|---|
| 118 | $cacheinfos = array(); |
|---|
| 119 | for ($i = 0; $i < $pcnt; $i ++) { |
|---|
| 120 | $data = xcache_info(XC_TYPE_PHP, $i); |
|---|
| 121 | if ($type === XC_TYPE_PHP) { |
|---|
| 122 | $data += xcache_list(XC_TYPE_PHP, $i); |
|---|
| 123 | } |
|---|
| 124 | $data['type'] = XC_TYPE_PHP; |
|---|
| 125 | $data['cache_name'] = "php#$i"; |
|---|
| 126 | $data['cacheid'] = $i; |
|---|
| 127 | $cacheinfos[] = $data; |
|---|
| 128 | } |
|---|
| 129 | for ($i = 0; $i < $vcnt; $i ++) { |
|---|
| 130 | $data = xcache_info(XC_TYPE_VAR, $i); |
|---|
| 131 | if ($type === XC_TYPE_VAR) { |
|---|
| 132 | $data += xcache_list(XC_TYPE_VAR, $i); |
|---|
| 133 | } |
|---|
| 134 | $data['type'] = XC_TYPE_VAR; |
|---|
| 135 | $data['cache_name'] = "var#$i"; |
|---|
| 136 | $data['cacheid'] = $i; |
|---|
| 137 | $cacheinfos[] = $data; |
|---|
| 138 | } |
|---|
| 139 | // }}} |
|---|
| 140 | // {{{ merge the list |
|---|
| 141 | switch ($type) { |
|---|
| 142 | case XC_TYPE_PHP: |
|---|
| 143 | case XC_TYPE_VAR: |
|---|
| 144 | $cachelist = array('type' => $type, 'cache_list' => array(), 'deleted_list' => array()); |
|---|
| 145 | if ($type == XC_TYPE_VAR) { |
|---|
| 146 | $cachelist['type_name'] = 'var'; |
|---|
| 147 | } |
|---|
| 148 | else { |
|---|
| 149 | $cachelist['type_name'] = 'php'; |
|---|
| 150 | } |
|---|
| 151 | foreach ($cacheinfos as $i => $c) { |
|---|
| 152 | if ($c['type'] == $type && isset($c['cache_list'])) { |
|---|
| 153 | foreach ($c['cache_list'] as $e) { |
|---|
| 154 | $e['cache_name'] = $c['cache_name']; |
|---|
| 155 | $cachelist['cache_list'][] = $e; |
|---|
| 156 | } |
|---|
| 157 | foreach ($c['deleted_list'] as $e) { |
|---|
| 158 | $e['cache_name'] = $c['cache_name']; |
|---|
| 159 | $cachelist['deleted_list'][] = $e; |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | if ($type == XC_TYPE_PHP) { |
|---|
| 164 | $inodes = array(); |
|---|
| 165 | foreach ($cachelist['cache_list'] as $e) { |
|---|
| 166 | $i = &$inodes[$e['inode']]; |
|---|
| 167 | if (isset($i) && $i == 1) { |
|---|
| 168 | set_error("duplicate inode $e[inode]"); |
|---|
| 169 | } |
|---|
| 170 | $i ++; |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | unset($data); |
|---|
| 174 | break; |
|---|
| 175 | |
|---|
| 176 | default: |
|---|
| 177 | $_GET['type'] = $type_none; |
|---|
| 178 | $cachelist = array(); |
|---|
| 179 | break; |
|---|
| 180 | } |
|---|
| 181 | // }}} |
|---|
| 182 | |
|---|
| 183 | $type_php = XC_TYPE_PHP; |
|---|
| 184 | $type_var = XC_TYPE_VAR; |
|---|
| 185 | $types = array($type_none => 'Statistics', $type_php =>'List PHP', $type_var =>'List Var Data'); |
|---|
| 186 | |
|---|
| 187 | include("xcache.tpl.php"); |
|---|
| 188 | |
|---|
| 189 | ?> |
|---|