Changeset 1078 for trunk/htdocs/cacher/index.php
- Timestamp:
- 2012-07-29T08:45:04+02:00 (10 months ago)
- File:
-
- 1 edited
-
trunk/htdocs/cacher/index.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/htdocs/cacher/index.php
r1074 r1078 1 1 <?php 2 2 3 include ("./common.php");4 5 function freeblock_to_graph($freeblocks, $size) 3 include "./common.php"; 4 5 function freeblock_to_graph($freeblocks, $size) // {{{ 6 6 { 7 7 global $config; … … 42 42 return implode('', $html); 43 43 } 44 45 function calc_total(&$total, $data) 44 // }}} 45 function calc_total(&$total, $data) // {{{ 46 46 { 47 47 foreach ($data as $k => $v) { … … 71 71 } 72 72 } 73 74 function array_avg($a) 73 // }}} 74 function array_avg($a) // {{{ 75 75 { 76 76 if (count($a) == 0) { … … 79 79 return array_sum($a) / count($a); 80 80 } 81 82 function bar_hits_percent($v, $percent, $active) 81 // }}} 82 function bar_hits_percent($v, $percent, $active) // {{{ 83 83 { 84 84 $r = 220 + (int) ($percent * 25); … … 96 96 . '</div>'; 97 97 } 98 99 function get_cache_hits_graph($ci, $key) 100 { 98 // }}} 99 function get_cache_hits_graph($ci, $key) // {{{ 100 { 101 global $maxHitsByHour; 101 102 if ($ci['cacheid'] == -1) { 102 103 $max = max($ci[$key]); 103 104 } 104 105 else { 105 $max = $ GLOBALS['maxhits_by_hour'][$ci['type']];106 $max = $maxHitsByHour[$ci['type']]; 106 107 } 107 108 if (!$max) { … … 115 116 return implode('', $html); 116 117 } 117 118 function getModuleInfo() 118 // }}} 119 function getModuleInfo() // {{{ 119 120 { 120 121 ob_start(); … … 132 133 return implode('', $moduleInfo); 133 134 } 135 // }}} 136 function getCacheInfos() // {{{ 137 { 138 static $cacheInfos; 139 if (isset($cacheInfos)) { 140 return $cacheInfos; 141 } 142 143 $phpCacheCount = xcache_count(XC_TYPE_PHP); 144 $varCacheCount = xcache_count(XC_TYPE_VAR); 145 146 $cacheInfos = array(); 147 $total = array(); 148 global $maxHitsByHour; 149 $maxHitsByHour = array(0, 0); 150 for ($i = 0; $i < $phpCacheCount; $i ++) { 151 $data = xcache_info(XC_TYPE_PHP, $i); 152 if ($_GET['do'] === 'listphp') { 153 $data += xcache_list(XC_TYPE_PHP, $i); 154 } 155 $data['type'] = XC_TYPE_PHP; 156 $data['cache_name'] = "php#$i"; 157 $data['cacheid'] = $i; 158 $cacheInfos[] = $data; 159 $maxHitsByHour[XC_TYPE_PHP] = max($maxHitsByHour[XC_TYPE_PHP], max($data['hits_by_hour'])); 160 if ($phpCacheCount >= 2) { 161 calc_total($total, $data); 162 } 163 } 164 165 if ($phpCacheCount >= 2) { 166 $total['type'] = XC_TYPE_PHP; 167 $total['cache_name'] = _('Total'); 168 $total['cacheid'] = -1; 169 $total['gc'] = null; 170 $total['istotal'] = true; 171 unset($total['compiling']); 172 $cacheInfos[] = $total; 173 } 174 175 $total = array(); 176 for ($i = 0; $i < $varCacheCount; $i ++) { 177 $data = xcache_info(XC_TYPE_VAR, $i); 178 if ($_GET['do'] === 'listvar') { 179 $data += xcache_list(XC_TYPE_VAR, $i); 180 } 181 $data['type'] = XC_TYPE_VAR; 182 $data['cache_name'] = "var#$i"; 183 $data['cacheid'] = $i; 184 $cacheInfos[] = $data; 185 $maxHitsByHour[XC_TYPE_VAR] = max($maxHitsByHour[XC_TYPE_VAR], max($data['hits_by_hour'])); 186 if ($varCacheCount >= 2) { 187 calc_total($total, $data); 188 } 189 } 190 191 if ($varCacheCount >= 2) { 192 $total['type'] = XC_TYPE_VAR; 193 $total['cache_name'] = _('Total'); 194 $total['cacheid'] = -1; 195 $total['gc'] = null; 196 $total['istotal'] = true; 197 $cacheInfos[] = $total; 198 } 199 return $cacheInfos; 200 } 201 // }}} 202 function getEntryList() // {{{ 203 { 204 static $entryList; 205 if (isset($entryList)) { 206 return $entryList; 207 } 208 $entryList = array('cache_list' => array(), 'deleted_list' => array()); 209 if ($_GET['do'] == 'listphp') { 210 $entryList['type_name'] = 'php'; 211 $entryList['type'] = XC_TYPE_PHP; 212 } 213 else { 214 $entryList['type_name'] = 'var'; 215 $entryList['type'] = XC_TYPE_VAR; 216 } 217 foreach (getCacheInfos() as $i => $c) { 218 if (!empty($c['istotal'])) { 219 continue; 220 } 221 if ($c['type'] == $entryList['type'] && isset($c['cache_list'])) { 222 foreach ($c['cache_list'] as $e) { 223 $e['cache_name'] = $c['cache_name']; 224 $entryList['cache_list'][] = $e; 225 } 226 foreach ($c['deleted_list'] as $e) { 227 $e['cache_name'] = $c['cache_name']; 228 $entryList['deleted_list'][] = $e; 229 } 230 } 231 } 232 return $entryList; 233 } 234 // }}} 134 235 135 236 $module = "cacher"; 136 237 if (!extension_loaded('XCache')) { 137 include ("../common/header.tpl.php");238 include "../common/header.tpl.php"; 138 239 echo '<h1>XCache is not loaded</h1>'; 139 240 ob_start(); … … 158 259 } 159 260 echo "(See above)"; 160 include ("../common/footer.tpl.php");261 include "../common/footer.tpl.php"; 161 262 exit; 162 263 } 163 $pcnt = xcache_count(XC_TYPE_PHP); 164 $vcnt = xcache_count(XC_TYPE_VAR); 165 166 if ($_SERVER['REQUEST_METHOD'] == 'POST') { 167 $remove = @ $_POST['remove']; 168 if ($remove && is_array($remove)) { 169 foreach ($remove as $name) { 170 xcache_unset($name); 171 } 172 } 173 } 174 175 $listTypes = array('' => _('Summary'), 'listphp' => _('List PHP'), 'listvar' => _('List Var Data')); 176 177 if (!isset($_GET['do'])) { 178 $_GET['do'] = ''; 179 } 180 181 // {{{ process clear, enable, disable 182 function processAction() 183 { 264 265 $doTypes = array( 266 '' => _('Summary'), 267 'listphp' => _('List PHP'), 268 'listvar' => _('List Var Data'), 269 'help' => _('Help'), 270 ); 271 272 function processPOST() // {{{ 273 { 274 if (isset($_POST['remove']) && is_array($_POST['remove'])) { 275 foreach ($_POST['remove'] as $name) { 276 if (is_string($name)) { 277 xcache_unset($name); 278 } 279 } 280 } 281 184 282 $type = isset($_POST['type']) ? $_POST['type'] : null; 185 283 if ($type != XC_TYPE_PHP && $type != XC_TYPE_VAR) { … … 198 296 } 199 297 } 200 } 201 processAction(); 202 if (isset($_POST['coredump'])) { 203 xcache_coredump(); 204 } 205 // }}} 206 // {{{ load info/list 207 $cacheinfos = array(); 208 $total = array(); 209 $maxhits_by_hour = array(0, 0); 210 for ($i = 0; $i < $pcnt; $i ++) { 211 $data = xcache_info(XC_TYPE_PHP, $i); 212 if ($_GET['do'] === 'listphp') { 213 $data += xcache_list(XC_TYPE_PHP, $i); 214 } 215 $data['type'] = XC_TYPE_PHP; 216 $data['cache_name'] = "php#$i"; 217 $data['cacheid'] = $i; 218 $cacheinfos[] = $data; 219 $maxhits_by_hour[XC_TYPE_PHP] = max($maxhits_by_hour[XC_TYPE_PHP], max($data['hits_by_hour'])); 220 if ($pcnt >= 2) { 221 calc_total($total, $data); 222 } 223 } 224 225 if ($pcnt >= 2) { 226 $total['type'] = XC_TYPE_PHP; 227 $total['cache_name'] = _('Total'); 228 $total['cacheid'] = -1; 229 $total['gc'] = null; 230 $total['istotal'] = true; 231 unset($total['compiling']); 232 $cacheinfos[] = $total; 233 } 234 235 $total = array(); 236 for ($i = 0; $i < $vcnt; $i ++) { 237 $data = xcache_info(XC_TYPE_VAR, $i); 238 if ($_GET['do'] === 'listvar') { 239 $data += xcache_list(XC_TYPE_VAR, $i); 240 } 241 $data['type'] = XC_TYPE_VAR; 242 $data['cache_name'] = "var#$i"; 243 $data['cacheid'] = $i; 244 $cacheinfos[] = $data; 245 $maxhits_by_hour[XC_TYPE_VAR] = max($maxhits_by_hour[XC_TYPE_VAR], max($data['hits_by_hour'])); 246 if ($vcnt >= 2) { 247 calc_total($total, $data); 248 } 249 } 250 251 if ($vcnt >= 2) { 252 $total['type'] = XC_TYPE_VAR; 253 $total['cache_name'] = _('Total'); 254 $total['cacheid'] = -1; 255 $total['gc'] = null; 256 $total['istotal'] = true; 257 $cacheinfos[] = $total; 258 } 259 // }}} 260 // {{{ merge the list 298 299 if (isset($_POST['coredump'])) { 300 xcache_coredump(); 301 } 302 } 303 // }}} 304 305 processPOST(); 306 307 if (!isset($_GET['do'])) { 308 $_GET['do'] = ''; 309 } 310 261 311 switch ($_GET['do']) { 262 312 case 'listphp': 263 313 case 'listvar': 264 $cachelist = array('cache_list' => array(), 'deleted_list' => array()); 265 if ($_GET['do'] == 'listphp') { 266 $cachelist['type_name'] = 'php'; 267 $cachelist['type'] = XC_TYPE_PHP; 268 } 269 else { 270 $cachelist['type_name'] = 'var'; 271 $cachelist['type'] = XC_TYPE_VAR; 272 } 273 foreach ($cacheinfos as $i => $c) { 274 if (!empty($c['istotal'])) { 275 continue; 276 } 277 if ($c['type'] == $cachelist['type'] && isset($c['cache_list'])) { 278 foreach ($c['cache_list'] as $e) { 279 $e['cache_name'] = $c['cache_name']; 280 $cachelist['cache_list'][] = $e; 281 } 282 foreach ($c['deleted_list'] as $e) { 283 $e['cache_name'] = $c['cache_name']; 284 $cachelist['deleted_list'][] = $e; 285 } 286 } 287 } 288 if ($cachelist['type'] == XC_TYPE_PHP) { 289 $inodes = array(); 290 $haveinode = false; 291 foreach ($cachelist['cache_list'] as $e) { 292 if (isset($e['file_inode'])) { 293 $haveinode = true; 294 break; 295 } 296 } 297 if (!$haveinode) { 298 foreach ($cachelist['deleted_list'] as $e) { 299 if (isset($e['file_inode'])) { 300 $haveinode = true; 301 break; 302 } 303 } 304 } 305 } 306 unset($data); 307 include("./listentries.tpl.php"); 314 include "./listentries.tpl.php"; 308 315 break; 309 316 317 case 'help': 318 include "./help.tpl.php"; 319 break; 320 310 321 default: 311 include ("./summary.tpl.php");312 } 313 // }}}322 include "./summary.tpl.php"; 323 break; 324 } 314 325 315 326 ?>
Note: See TracChangeset
for help on using the changeset viewer.

