apc.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. <?php
  2. {% if ansible_prolog -%}
  3. {% from 'templates/ansible/prolog.j2' import prolog with context %}
  4. {{ prolog('//') }}
  5. {% endif -%}
  6. /*
  7. +----------------------------------------------------------------------+
  8. | APC |
  9. +----------------------------------------------------------------------+
  10. | Copyright (c) 2006-2011 The PHP Group |
  11. +----------------------------------------------------------------------+
  12. | This source file is subject to version 3.01 of the PHP license, |
  13. | that is bundled with this package in the file LICENSE, and is |
  14. | available through the world-wide-web at the following url: |
  15. | http://www.php.net/license/3_01.txt |
  16. | If you did not receive a copy of the PHP license and are unable to |
  17. | obtain it through the world-wide-web, please send a note to |
  18. | license@php.net so we can mail you a copy immediately. |
  19. +----------------------------------------------------------------------+
  20. | Authors: Ralf Becker <beckerr@php.net> |
  21. | Rasmus Lerdorf <rasmus@php.net> |
  22. | Ilia Alshanetsky <ilia@prohost.org> |
  23. +----------------------------------------------------------------------+
  24. All other licensing and usage conditions are those of the PHP Group.
  25. */
  26. $VERSION='$Id$';
  27. ////////// READ OPTIONAL CONFIGURATION FILE ////////////
  28. if (file_exists("apc.conf.php")) include("apc.conf.php");
  29. ////////////////////////////////////////////////////////
  30. ////////// BEGIN OF DEFAULT CONFIG AREA ///////////////////////////////////////////////////////////
  31. defaults('USE_AUTHENTICATION',0); // Use (internal) authentication - best choice if
  32. // no other authentication is available
  33. // If set to 0:
  34. // There will be no further authentication. You
  35. // will have to handle this by yourself!
  36. // If set to 1:
  37. // You need to change ADMIN_PASSWORD to make
  38. // this work!
  39. defaults('ADMIN_USERNAME','apc'); // Admin Username
  40. defaults('ADMIN_PASSWORD','password'); // Admin Password - CHANGE THIS TO ENABLE!!!
  41. // (beckerr) I'm using a clear text password here, because I've no good idea how to let
  42. // users generate a md5 or crypt password in a easy way to fill it in above
  43. //defaults('DATE_FORMAT', "d.m.Y H:i:s"); // German
  44. defaults('DATE_FORMAT', 'Y/m/d H:i:s'); // US
  45. defaults('GRAPH_SIZE',200); // Image size
  46. //defaults('PROXY', 'tcp://127.0.0.1:8080');
  47. ////////// END OF DEFAULT CONFIG AREA /////////////////////////////////////////////////////////////
  48. // "define if not defined"
  49. function defaults($d,$v) {
  50. if (!defined($d)) define($d,$v); // or just @define(...)
  51. }
  52. // rewrite $PHP_SELF to block XSS attacks
  53. //
  54. $PHP_SELF= isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],''), ENT_QUOTES, 'UTF-8') : '';
  55. $time = time();
  56. $host = php_uname('n');
  57. if($host) { $host = '('.$host.')'; }
  58. if (isset($_SERVER['SERVER_ADDR'])) {
  59. $host .= ' ('.$_SERVER['SERVER_ADDR'].')';
  60. }
  61. // operation constants
  62. define('OB_HOST_STATS',1);
  63. define('OB_USER_CACHE',2);
  64. define('OB_VERSION_CHECK',3);
  65. // check validity of input variables
  66. $vardom=array(
  67. 'OB' => '/^\d+$/', // operational mode switch
  68. 'CC' => '/^[01]$/', // clear cache requested
  69. 'DU' => '/^.*$/', // Delete User Key
  70. 'SH' => '/^[a-z0-9]+$/', // shared object description
  71. 'IMG' => '/^[123]$/', // image to generate
  72. 'LO' => '/^1$/', // login requested
  73. 'COUNT' => '/^\d+$/', // number of line displayed in list
  74. 'SCOPE' => '/^[AD]$/', // list view scope
  75. 'SORT1' => '/^[AHSMCDTZ]$/', // first sort key
  76. 'SORT2' => '/^[DA]$/', // second sort key
  77. 'AGGR' => '/^\d+$/', // aggregation by dir level
  78. 'SEARCH' => '~^[a-zA-Z0-9/_.-]*$~' // aggregation by dir level
  79. );
  80. // cache scope
  81. $scope_list=array(
  82. 'A' => 'cache_list',
  83. 'D' => 'deleted_list'
  84. );
  85. // handle POST and GET requests
  86. if (empty($_REQUEST)) {
  87. if (!empty($_GET) && !empty($_POST)) {
  88. $_REQUEST = array_merge($_GET, $_POST);
  89. } else if (!empty($_GET)) {
  90. $_REQUEST = $_GET;
  91. } else if (!empty($_POST)) {
  92. $_REQUEST = $_POST;
  93. } else {
  94. $_REQUEST = array();
  95. }
  96. }
  97. // check parameter syntax
  98. foreach($vardom as $var => $dom) {
  99. if (!isset($_REQUEST[$var])) {
  100. $MYREQUEST[$var]=NULL;
  101. } else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D',$_REQUEST[$var])) {
  102. $MYREQUEST[$var]=$_REQUEST[$var];
  103. } else {
  104. $MYREQUEST[$var]=$_REQUEST[$var]=NULL;
  105. }
  106. }
  107. // check parameter sematics
  108. if (empty($MYREQUEST['SCOPE'])) $MYREQUEST['SCOPE']="A";
  109. if (empty($MYREQUEST['SORT1'])) $MYREQUEST['SORT1']="H";
  110. if (empty($MYREQUEST['SORT2'])) $MYREQUEST['SORT2']="D";
  111. if (empty($MYREQUEST['OB'])) $MYREQUEST['OB']=OB_HOST_STATS;
  112. if (!isset($MYREQUEST['COUNT'])) $MYREQUEST['COUNT']=20;
  113. if (!isset($scope_list[$MYREQUEST['SCOPE']])) $MYREQUEST['SCOPE']='A';
  114. $MY_SELF=
  115. "$PHP_SELF".
  116. "?SCOPE=".$MYREQUEST['SCOPE'].
  117. "&SORT1=".$MYREQUEST['SORT1'].
  118. "&SORT2=".$MYREQUEST['SORT2'].
  119. "&COUNT=".$MYREQUEST['COUNT'];
  120. $MY_SELF_WO_SORT=
  121. "$PHP_SELF".
  122. "?SCOPE=".$MYREQUEST['SCOPE'].
  123. "&COUNT=".$MYREQUEST['COUNT'];
  124. // authentication needed?
  125. //
  126. if (!USE_AUTHENTICATION) {
  127. $AUTHENTICATED=1;
  128. } else {
  129. $AUTHENTICATED=0;
  130. if (ADMIN_PASSWORD!='password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
  131. if (!isset($_SERVER['PHP_AUTH_USER']) ||
  132. !isset($_SERVER['PHP_AUTH_PW']) ||
  133. $_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME ||
  134. $_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD) {
  135. Header("WWW-Authenticate: Basic realm=\"APC Login\"");
  136. Header("HTTP/1.0 401 Unauthorized");
  137. echo <<<EOB
  138. <html><body>
  139. <h1>Rejected!</h1>
  140. <big>Wrong Username or Password!</big><br/>&nbsp;<br/>&nbsp;
  141. <big><a href='$PHP_SELF?OB={$MYREQUEST['OB']}'>Continue...</a></big>
  142. </body></html>
  143. EOB;
  144. exit;
  145. } else {
  146. $AUTHENTICATED=1;
  147. }
  148. }
  149. }
  150. // clear cache
  151. if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) {
  152. apcu_clear_cache();
  153. }
  154. if ($AUTHENTICATED && !empty($MYREQUEST['DU'])) {
  155. apcu_delete($MYREQUEST['DU']);
  156. }
  157. if(!function_exists('apcu_cache_info')) {
  158. echo "No cache info available. APC does not appear to be running.";
  159. exit;
  160. }
  161. $cache = apcu_cache_info();
  162. $mem=apcu_sma_info();
  163. // don't cache this page
  164. //
  165. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  166. header("Cache-Control: post-check=0, pre-check=0", false);
  167. header("Pragma: no-cache"); // HTTP/1.0
  168. function duration($ts) {
  169. global $time;
  170. $years = (int)((($time - $ts)/(7*86400))/52.177457);
  171. $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
  172. $weeks = (int)(($rem)/(7*86400));
  173. $days = (int)(($rem)/86400) - $weeks*7;
  174. $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
  175. $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
  176. $str = '';
  177. if($years==1) $str .= "$years year, ";
  178. if($years>1) $str .= "$years years, ";
  179. if($weeks==1) $str .= "$weeks week, ";
  180. if($weeks>1) $str .= "$weeks weeks, ";
  181. if($days==1) $str .= "$days day,";
  182. if($days>1) $str .= "$days days,";
  183. if($hours == 1) $str .= " $hours hour and";
  184. if($hours>1) $str .= " $hours hours and";
  185. if($mins == 1) $str .= " 1 minute";
  186. else $str .= " $mins minutes";
  187. return $str;
  188. }
  189. // create graphics
  190. //
  191. function graphics_avail() {
  192. return extension_loaded('gd');
  193. }
  194. if (isset($MYREQUEST['IMG']))
  195. {
  196. if (!graphics_avail()) {
  197. exit(0);
  198. }
  199. function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$color2,$text='',$placeindex=0) {
  200. $r=$diameter/2;
  201. $w=deg2rad((360+$start+($end-$start)/2)%360);
  202. if (function_exists("imagefilledarc")) {
  203. // exists only if GD 2.0.1 is avaliable
  204. imagefilledarc($im, $centerX+1, $centerY+1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
  205. imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2, IMG_ARC_PIE);
  206. imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL|IMG_ARC_EDGED);
  207. } else {
  208. imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2);
  209. imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
  210. imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start+1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
  211. imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end-1)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
  212. imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
  213. imagefill($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $color2);
  214. }
  215. if ($text) {
  216. if ($placeindex>0) {
  217. imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
  218. imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
  219. } else {
  220. imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
  221. }
  222. }
  223. }
  224. function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$text,$placeindex=0) {
  225. $r=$diameter/2;
  226. $w=deg2rad((360+$start+($end-$start)/2)%360);
  227. if ($placeindex>0) {
  228. imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
  229. imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
  230. } else {
  231. imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
  232. }
  233. }
  234. function fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='') {
  235. global $col_black;
  236. $x1=$x+$w-1;
  237. $y1=$y+$h-1;
  238. imagerectangle($im, $x, $y1, $x1+1, $y+1, $col_black);
  239. if($y1>$y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
  240. else imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
  241. imagerectangle($im, $x, $y1, $x1, $y, $color1);
  242. if ($text) {
  243. if ($placeindex>0) {
  244. if ($placeindex<16)
  245. {
  246. $px=5;
  247. $py=$placeindex*12+6;
  248. imagefilledrectangle($im, $px+90, $py+3, $px+90-4, $py-3, $color2);
  249. imageline($im,$x,$y+$h/2,$px+90,$py,$color2);
  250. imagestring($im,2,$px,$py-6,$text,$color1);
  251. } else {
  252. if ($placeindex<31) {
  253. $px=$x+40*2;
  254. $py=($placeindex-15)*12+6;
  255. } else {
  256. $px=$x+40*2+100*intval(($placeindex-15)/15);
  257. $py=($placeindex%15)*12+6;
  258. }
  259. imagefilledrectangle($im, $px, $py+3, $px-4, $py-3, $color2);
  260. imageline($im,$x+$w,$y+$h/2,$px,$py,$color2);
  261. imagestring($im,2,$px+2,$py-6,$text,$color1);
  262. }
  263. } else {
  264. imagestring($im,4,$x+5,$y1-16,$text,$color1);
  265. }
  266. }
  267. }
  268. $size = GRAPH_SIZE; // image size
  269. if ($MYREQUEST['IMG']==3)
  270. $image = imagecreate(2*$size+150, $size+10);
  271. else
  272. $image = imagecreate($size+50, $size+10);
  273. $col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
  274. $col_red = imagecolorallocate($image, 0xD0, 0x60, 0x30);
  275. $col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
  276. $col_black = imagecolorallocate($image, 0, 0, 0);
  277. imagecolortransparent($image,$col_white);
  278. switch ($MYREQUEST['IMG']) {
  279. case 1:
  280. $s=$mem['num_seg']*$mem['seg_size'];
  281. $a=$mem['avail_mem'];
  282. $x=$y=$size/2;
  283. $fuzz = 0.000001;
  284. // This block of code creates the pie chart. It is a lot more complex than you
  285. // would expect because we try to visualize any memory fragmentation as well.
  286. $angle_from = 0;
  287. $string_placement=array();
  288. for($i=0; $i<$mem['num_seg']; $i++) {
  289. $ptr = 0;
  290. $free = $mem['block_lists'][$i];
  291. uasort($free, 'block_sort');
  292. foreach($free as $block) {
  293. if($block['offset']!=$ptr) { // Used block
  294. $angle_to = $angle_from+($block['offset']-$ptr)/$s;
  295. if(($angle_to+$fuzz)>1) $angle_to = 1;
  296. if( ($angle_to*360) - ($angle_from*360) >= 1) {
  297. fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
  298. if (($angle_to-$angle_from)>0.05) {
  299. array_push($string_placement, array($angle_from,$angle_to));
  300. }
  301. }
  302. $angle_from = $angle_to;
  303. }
  304. $angle_to = $angle_from+($block['size'])/$s;
  305. if(($angle_to+$fuzz)>1) $angle_to = 1;
  306. if( ($angle_to*360) - ($angle_from*360) >= 1) {
  307. fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_green);
  308. if (($angle_to-$angle_from)>0.05) {
  309. array_push($string_placement, array($angle_from,$angle_to));
  310. }
  311. }
  312. $angle_from = $angle_to;
  313. $ptr = $block['offset']+$block['size'];
  314. }
  315. if ($ptr < $mem['seg_size']) { // memory at the end
  316. $angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
  317. if(($angle_to+$fuzz)>1) $angle_to = 1;
  318. fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
  319. if (($angle_to-$angle_from)>0.05) {
  320. array_push($string_placement, array($angle_from,$angle_to));
  321. }
  322. }
  323. }
  324. foreach ($string_placement as $angle) {
  325. text_arc($image,$x,$y,$size,$angle[0]*360,$angle[1]*360,$col_black,bsize($s*($angle[1]-$angle[0])));
  326. }
  327. break;
  328. case 2:
  329. $s=$cache['num_hits']+$cache['num_misses'];
  330. $a=$cache['num_hits'];
  331. fill_box($image, 30,$size,50,$s ? (-$a*($size-21)/$s) : 0,$col_black,$col_green,sprintf("%.1f%%",$s ? $cache['num_hits']*100/$s : 0));
  332. fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%",$s ? $cache['num_misses']*100/$s : 0));
  333. break;
  334. case 3:
  335. $s=$mem['num_seg']*$mem['seg_size'];
  336. $a=$mem['avail_mem'];
  337. $x=130;
  338. $y=1;
  339. $j=1;
  340. // This block of code creates the bar chart. It is a lot more complex than you
  341. // would expect because we try to visualize any memory fragmentation as well.
  342. for($i=0; $i<$mem['num_seg']; $i++) {
  343. $ptr = 0;
  344. $free = $mem['block_lists'][$i];
  345. uasort($free, 'block_sort');
  346. foreach($free as $block) {
  347. if($block['offset']!=$ptr) { // Used block
  348. $h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
  349. if ($h>0) {
  350. $j++;
  351. if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
  352. else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
  353. }
  354. $y+=$h;
  355. }
  356. $h=(GRAPH_SIZE-5)*($block['size'])/$s;
  357. if ($h>0) {
  358. $j++;
  359. if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
  360. else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
  361. }
  362. $y+=$h;
  363. $ptr = $block['offset']+$block['size'];
  364. }
  365. if ($ptr < $mem['seg_size']) { // memory at the end
  366. $h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
  367. if ($h > 0) {
  368. fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
  369. }
  370. }
  371. }
  372. break;
  373. case 4:
  374. $s=$cache['num_hits']+$cache['num_misses'];
  375. $a=$cache['num_hits'];
  376. fill_box($image, 30,$size,50,$s ? -$a*($size-21)/$s : 0,$col_black,$col_green,sprintf("%.1f%%", $s ? $cache['num_hits']*100/$s : 0));
  377. fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%", $s ? $cache['num_misses']*100/$s : 0));
  378. break;
  379. }
  380. header("Content-type: image/png");
  381. imagepng($image);
  382. exit;
  383. }
  384. // pretty printer for byte values
  385. //
  386. function bsize($s) {
  387. foreach (array('','K','M','G') as $i => $k) {
  388. if ($s < 1024) break;
  389. $s/=1024;
  390. }
  391. return sprintf("%5.1f %sBytes",$s,$k);
  392. }
  393. // sortable table header in "scripts for this host" view
  394. function sortheader($key,$name,$extra='') {
  395. global $MYREQUEST, $MY_SELF_WO_SORT;
  396. if ($MYREQUEST['SORT1']==$key) {
  397. $MYREQUEST['SORT2'] = $MYREQUEST['SORT2']=='A' ? 'D' : 'A';
  398. }
  399. return "<a class=sortable href=\"$MY_SELF_WO_SORT$extra&SORT1=$key&SORT2=".$MYREQUEST['SORT2']."\">$name</a>";
  400. }
  401. // create menu entry
  402. function menu_entry($ob,$title) {
  403. global $MYREQUEST,$MY_SELF;
  404. if ($MYREQUEST['OB']!=$ob) {
  405. return "<li><a href=\"$MY_SELF&OB=$ob\">$title</a></li>";
  406. } else if (empty($MYREQUEST['SH'])) {
  407. return "<li><span class=active>$title</span></li>";
  408. } else {
  409. return "<li><a class=\"child_active\" href=\"$MY_SELF&OB=$ob\">$title</a></li>";
  410. }
  411. }
  412. function put_login_link($s="Login")
  413. {
  414. global $MY_SELF,$MYREQUEST,$AUTHENTICATED;
  415. // needs ADMIN_PASSWORD to be changed!
  416. //
  417. if (!USE_AUTHENTICATION) {
  418. return;
  419. } else if (ADMIN_PASSWORD=='password')
  420. {
  421. print <<<EOB
  422. <a href="#" onClick="javascript:alert('You need to set a password at the top of apc.php before this will work!');return false";>$s</a>
  423. EOB;
  424. } else if ($AUTHENTICATED) {
  425. print <<<EOB
  426. '{$_SERVER['PHP_AUTH_USER']}'&nbsp;logged&nbsp;in!
  427. EOB;
  428. } else{
  429. print <<<EOB
  430. <a href="$MY_SELF&LO=1&OB={$MYREQUEST['OB']}">$s</a>
  431. EOB;
  432. }
  433. }
  434. function block_sort($array1, $array2)
  435. {
  436. if ($array1['offset'] > $array2['offset']) {
  437. return 1;
  438. } else {
  439. return -1;
  440. }
  441. }
  442. ?>
  443. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  444. <html>
  445. <head><title>APCu INFO <?php echo $host ?></title>
  446. <style><!--
  447. body { background:white; font-size:100.01%; margin:0; padding:0; }
  448. body,p,td,th,input,submit { font-size:0.8em;font-family:arial,helvetica,sans-serif; }
  449. * html body {font-size:0.8em}
  450. * html p {font-size:0.8em}
  451. * html td {font-size:0.8em}
  452. * html th {font-size:0.8em}
  453. * html input {font-size:0.8em}
  454. * html submit {font-size:0.8em}
  455. td { vertical-align:top }
  456. a { color:black; font-weight:none; text-decoration:none; }
  457. a:hover { text-decoration:underline; }
  458. div.content { padding:1em 1em 1em 1em; position:absolute; width:97%; z-index:100; }
  459. div.head div.login {
  460. position:absolute;
  461. right: 1em;
  462. top: 1.2em;
  463. color:white;
  464. width:6em;
  465. }
  466. div.head div.login a {
  467. position:absolute;
  468. right: 0em;
  469. background:rgb(119,123,180);
  470. border:solid rgb(102,102,153) 2px;
  471. color:white;
  472. font-weight:bold;
  473. padding:0.1em 0.5em 0.1em 0.5em;
  474. text-decoration:none;
  475. }
  476. div.head div.login a:hover {
  477. background:rgb(193,193,244);
  478. }
  479. h1.apc { background:rgb(153,153,204); margin:0; padding:0.5em 1em 0.5em 1em; }
  480. * html h1.apc { margin-bottom:-7px; }
  481. h1.apc a:hover { text-decoration:none; color:rgb(90,90,90); }
  482. h1.apc div.logo span.logo {
  483. background:rgb(119,123,180);
  484. color:black;
  485. border-right: solid black 1px;
  486. border-bottom: solid black 1px;
  487. font-style:italic;
  488. font-size:1em;
  489. padding-left:1.2em;
  490. padding-right:1.2em;
  491. text-align:right;
  492. }
  493. h1.apc div.logo span.name { color:white; font-size:0.7em; padding:0 0.8em 0 2em; }
  494. h1.apc div.nameinfo { color:white; display:inline; font-size:0.4em; margin-left: 3em; }
  495. h1.apc div.copy { color:black; font-size:0.4em; position:absolute; right:1em; }
  496. hr.apc {
  497. background:white;
  498. border-bottom:solid rgb(102,102,153) 1px;
  499. border-style:none;
  500. border-top:solid rgb(102,102,153) 10px;
  501. height:12px;
  502. margin:0;
  503. margin-top:1px;
  504. padding:0;
  505. }
  506. ol,menu { margin:1em 0 0 0; padding:0.2em; margin-left:1em;}
  507. ol.menu li { display:inline; margin-right:0.7em; list-style:none; font-size:85%}
  508. ol.menu a {
  509. background:rgb(153,153,204);
  510. border:solid rgb(102,102,153) 2px;
  511. color:white;
  512. font-weight:bold;
  513. margin-right:0em;
  514. padding:0.1em 0.5em 0.1em 0.5em;
  515. text-decoration:none;
  516. margin-left: 5px;
  517. }
  518. ol.menu a.child_active {
  519. background:rgb(153,153,204);
  520. border:solid rgb(102,102,153) 2px;
  521. color:white;
  522. font-weight:bold;
  523. margin-right:0em;
  524. padding:0.1em 0.5em 0.1em 0.5em;
  525. text-decoration:none;
  526. border-left: solid black 5px;
  527. margin-left: 0px;
  528. }
  529. ol.menu span.active {
  530. background:rgb(153,153,204);
  531. border:solid rgb(102,102,153) 2px;
  532. color:black;
  533. font-weight:bold;
  534. margin-right:0em;
  535. padding:0.1em 0.5em 0.1em 0.5em;
  536. text-decoration:none;
  537. border-left: solid black 5px;
  538. }
  539. ol.menu span.inactive {
  540. background:rgb(193,193,244);
  541. border:solid rgb(182,182,233) 2px;
  542. color:white;
  543. font-weight:bold;
  544. margin-right:0em;
  545. padding:0.1em 0.5em 0.1em 0.5em;
  546. text-decoration:none;
  547. margin-left: 5px;
  548. }
  549. ol.menu a:hover {
  550. background:rgb(193,193,244);
  551. text-decoration:none;
  552. }
  553. div.info {
  554. background:rgb(204,204,204);
  555. border:solid rgb(204,204,204) 1px;
  556. margin-bottom:1em;
  557. }
  558. div.info h2 {
  559. background:rgb(204,204,204);
  560. color:black;
  561. font-size:1em;
  562. margin:0;
  563. padding:0.1em 1em 0.1em 1em;
  564. }
  565. div.info table {
  566. border:solid rgb(204,204,204) 1px;
  567. border-spacing:0;
  568. width:100%;
  569. }
  570. div.info table th {
  571. background:rgb(204,204,204);
  572. color:white;
  573. margin:0;
  574. padding:0.1em 1em 0.1em 1em;
  575. }
  576. div.info table th a.sortable { color:black; }
  577. div.info table tr.tr-0 { background:rgb(238,238,238); }
  578. div.info table tr.tr-1 { background:rgb(221,221,221); }
  579. div.info table td { padding:0.3em 1em 0.3em 1em; }
  580. div.info table td.td-0 { border-right:solid rgb(102,102,153) 1px; white-space:nowrap; }
  581. div.info table td.td-n { border-right:solid rgb(102,102,153) 1px; }
  582. div.info table td h3 {
  583. color:black;
  584. font-size:1.1em;
  585. margin-left:-0.3em;
  586. }
  587. div.graph { margin-bottom:1em }
  588. div.graph h2 { background:rgb(204,204,204);; color:black; font-size:1em; margin:0; padding:0.1em 1em 0.1em 1em; }
  589. div.graph table { border:solid rgb(204,204,204) 1px; color:black; font-weight:normal; width:100%; }
  590. div.graph table td.td-0 { background:rgb(238,238,238); }
  591. div.graph table td.td-1 { background:rgb(221,221,221); }
  592. div.graph table td { padding:0.2em 1em 0.4em 1em; }
  593. div.div1,div.div2 { margin-bottom:1em; width:35em; }
  594. div.div3 { position:absolute; left:40em; top:1em; width:580px; }
  595. //div.div3 { position:absolute; left:37em; top:1em; right:1em; }
  596. div.sorting { margin:1.5em 0em 1.5em 2em }
  597. .center { text-align:center }
  598. .aright { position:absolute;right:1em }
  599. .right { text-align:right }
  600. .ok { color:rgb(0,200,0); font-weight:bold}
  601. .failed { color:rgb(200,0,0); font-weight:bold}
  602. span.box {
  603. border: black solid 1px;
  604. border-right:solid black 2px;
  605. border-bottom:solid black 2px;
  606. padding:0 0.5em 0 0.5em;
  607. margin-right:1em;
  608. }
  609. span.green { background:#60F060; padding:0 0.5em 0 0.5em}
  610. span.red { background:#D06030; padding:0 0.5em 0 0.5em }
  611. div.authneeded {
  612. background:rgb(238,238,238);
  613. border:solid rgb(204,204,204) 1px;
  614. color:rgb(200,0,0);
  615. font-size:1.2em;
  616. font-weight:bold;
  617. padding:2em;
  618. text-align:center;
  619. }
  620. input {
  621. background:rgb(153,153,204);
  622. border:solid rgb(102,102,153) 2px;
  623. color:white;
  624. font-weight:bold;
  625. margin-right:1em;
  626. padding:0.1em 0.5em 0.1em 0.5em;
  627. }
  628. //-->
  629. </style>
  630. </head>
  631. <body>
  632. <div class="head">
  633. <h1 class="apc">
  634. <div class="logo"><span class="logo"><a href="http://pecl.php.net/package/APCu">APCu</a></span></div>
  635. <div class="nameinfo">User Cache</div>
  636. </h1>
  637. <div class="login">
  638. <?php put_login_link(); ?>
  639. </div>
  640. <hr class="apc">
  641. </div>
  642. <?php
  643. // Display main Menu
  644. echo <<<EOB
  645. <ol class=menu>
  646. <li><a href="$MY_SELF&OB={$MYREQUEST['OB']}&SH={$MYREQUEST['SH']}">Refresh Data</a></li>
  647. EOB;
  648. echo
  649. menu_entry(OB_HOST_STATS,'View Host Stats'),
  650. menu_entry(OB_USER_CACHE,'User Cache Entries'),
  651. menu_entry(OB_VERSION_CHECK,'Version Check');
  652. if ($AUTHENTICATED) {
  653. echo <<<EOB
  654. <li><a class="aright" href="$MY_SELF&CC=1&OB={$MYREQUEST['OB']}" onClick="javascript:return confirm('Are you sure?');">Clear Cache</a></li>
  655. EOB;
  656. }
  657. echo <<<EOB
  658. </ol>
  659. EOB;
  660. // CONTENT
  661. echo <<<EOB
  662. <div class=content>
  663. EOB;
  664. // MAIN SWITCH STATEMENT
  665. switch ($MYREQUEST['OB']) {
  666. // -----------------------------------------------
  667. // Host Stats
  668. // -----------------------------------------------
  669. case OB_HOST_STATS:
  670. $mem_size = $mem['num_seg']*$mem['seg_size'];
  671. $mem_avail= $mem['avail_mem'];
  672. $mem_used = $mem_size-$mem_avail;
  673. $seg_size = bsize($mem['seg_size']);
  674. $req_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits']+$cache['num_misses'])/($time-$cache['start_time'])) : 0);
  675. $hit_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits'])/($time-$cache['start_time'])) : 0);
  676. $miss_rate_user = sprintf("%.2f", $cache['num_misses'] ? (($cache['num_misses'])/($time-$cache['start_time'])) : 0);
  677. $insert_rate_user = sprintf("%.2f", $cache['num_inserts'] ? (($cache['num_inserts'])/($time-$cache['start_time'])) : 0);
  678. $apcversion = phpversion('apcu');
  679. $phpversion = phpversion();
  680. $number_vars = $cache['num_entries'];
  681. $size_vars = bsize($cache['mem_size']);
  682. $i=0;
  683. echo <<< EOB
  684. <div class="info div1"><h2>General Cache Information</h2>
  685. <table cellspacing=0><tbody>
  686. <tr class=tr-0><td class=td-0>APCu Version</td><td>$apcversion</td></tr>
  687. <tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
  688. EOB;
  689. if(!empty($_SERVER['SERVER_NAME']))
  690. echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
  691. if(!empty($_SERVER['SERVER_SOFTWARE']))
  692. echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
  693. echo <<<EOB
  694. <tr class=tr-0><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size
  695. <br/> ({$cache['memory_type']} memory)
  696. </td></tr>
  697. EOB;
  698. echo '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>';
  699. echo '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>';
  700. echo <<<EOB
  701. </tbody></table>
  702. </div>
  703. <div class="info div1"><h2>Cache Information</h2>
  704. <table cellspacing=0>
  705. <tbody>
  706. <tr class=tr-0><td class=td-0>Cached Variables</td><td>$number_vars ($size_vars)</td></tr>
  707. <tr class=tr-1><td class=td-0>Hits</td><td>{$cache['num_hits']}</td></tr>
  708. <tr class=tr-0><td class=td-0>Misses</td><td>{$cache['num_misses']}</td></tr>
  709. <tr class=tr-1><td class=td-0>Request Rate (hits, misses)</td><td>$req_rate_user cache requests/second</td></tr>
  710. <tr class=tr-0><td class=td-0>Hit Rate</td><td>$hit_rate_user cache requests/second</td></tr>
  711. <tr class=tr-1><td class=td-0>Miss Rate</td><td>$miss_rate_user cache requests/second</td></tr>
  712. <tr class=tr-0><td class=td-0>Insert Rate</td><td>$insert_rate_user cache requests/second</td></tr>
  713. <tr class=tr-1><td class=td-0>Cache full count</td><td>{$cache['expunges']}</td></tr>
  714. </tbody>
  715. </table>
  716. </div>
  717. <div class="info div2"><h2>Runtime Settings</h2><table cellspacing=0><tbody>
  718. EOB;
  719. $j = 0;
  720. foreach (ini_get_all('apcu') as $k => $v) {
  721. echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n";
  722. $j = 1 - $j;
  723. }
  724. if($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1)
  725. $mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
  726. else
  727. $mem_note = "Memory Usage";
  728. echo <<< EOB
  729. </tbody></table>
  730. </div>
  731. <div class="graph div3"><h2>Host Status Diagrams</h2>
  732. <table cellspacing=0><tbody>
  733. EOB;
  734. $size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
  735. echo <<<EOB
  736. <tr>
  737. <td class=td-0>$mem_note</td>
  738. <td class=td-1>Hits &amp; Misses</td>
  739. </tr>
  740. EOB;
  741. echo
  742. graphics_avail() ?
  743. '<tr>'.
  744. "<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF?IMG=1&$time\"></td>".
  745. "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
  746. : "",
  747. '<tr>',
  748. '<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
  749. '<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$cache['num_hits'].@sprintf(" (%.1f%%)",$cache['num_hits']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n",
  750. '</tr>',
  751. '<tr>',
  752. '<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
  753. '<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$cache['num_misses'].@sprintf(" (%.1f%%)",$cache['num_misses']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n";
  754. echo <<< EOB
  755. </tr>
  756. </tbody></table>
  757. <br/>
  758. <h2>Detailed Memory Usage and Fragmentation</h2>
  759. <table cellspacing=0><tbody>
  760. <tr>
  761. <td class=td-0 colspan=2><br/>
  762. EOB;
  763. // Fragementation: (freeseg - 1) / total_seg
  764. $nseg = $freeseg = $fragsize = $freetotal = 0;
  765. for($i=0; $i<$mem['num_seg']; $i++) {
  766. $ptr = 0;
  767. foreach($mem['block_lists'][$i] as $block) {
  768. if ($block['offset'] != $ptr) {
  769. ++$nseg;
  770. }
  771. $ptr = $block['offset'] + $block['size'];
  772. /* Only consider blocks <5M for the fragmentation % */
  773. if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
  774. $freetotal+=$block['size'];
  775. }
  776. $freeseg += count($mem['block_lists'][$i]);
  777. }
  778. if ($freeseg > 1) {
  779. $frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg);
  780. } else {
  781. $frag = "0%";
  782. }
  783. if (graphics_avail()) {
  784. $size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
  785. echo <<<EOB
  786. <img alt="" $size src="$PHP_SELF?IMG=3&$time">
  787. EOB;
  788. }
  789. echo <<<EOB
  790. </br>Fragmentation: $frag
  791. </td>
  792. </tr>
  793. EOB;
  794. if(isset($mem['adist'])) {
  795. foreach($mem['adist'] as $i=>$v) {
  796. $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
  797. if($i==0) $range = "1";
  798. else $range = "$cur - $nxt";
  799. echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
  800. }
  801. }
  802. echo <<<EOB
  803. </tbody></table>
  804. </div>
  805. EOB;
  806. break;
  807. // -----------------------------------------------
  808. // User Cache Entries
  809. // -----------------------------------------------
  810. case OB_USER_CACHE:
  811. if (!$AUTHENTICATED) {
  812. echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
  813. put_login_link("Login now!");
  814. echo '</div>';
  815. break;
  816. }
  817. $fieldname='info';
  818. $fieldheading='User Entry Label';
  819. $fieldkey='info';
  820. $cols=6;
  821. echo <<<EOB
  822. <div class=sorting><form>Scope:
  823. <input type=hidden name=OB value={$MYREQUEST['OB']}>
  824. <select name=SCOPE>
  825. EOB;
  826. echo
  827. "<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
  828. "<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
  829. "</select>",
  830. ", Sorting:<select name=SORT1>",
  831. "<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Hits</option>",
  832. "<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Size</option>",
  833. "<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">$fieldheading</option>",
  834. "<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Last accessed</option>",
  835. "<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
  836. "<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
  837. "<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
  838. if($fieldname=='info') echo
  839. "<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
  840. echo
  841. '</select>',
  842. '<select name=SORT2>',
  843. '<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
  844. '<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
  845. '</select>',
  846. '<select name=COUNT onChange="form.submit()">',
  847. '<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
  848. '<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
  849. '<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
  850. '<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
  851. '<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
  852. '<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
  853. '<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
  854. '<option value=0 ',$MYREQUEST['COUNT']=='0' ? ' selected':'','>All</option>',
  855. '</select>',
  856. '&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
  857. '&nbsp;<input type=submit value="GO!">',
  858. '</form></div>';
  859. if (isset($MYREQUEST['SEARCH'])) {
  860. // Don't use preg_quote because we want the user to be able to specify a
  861. // regular expression subpattern.
  862. $MYREQUEST['SEARCH'] = '/'.str_replace('/', '\\/', $MYREQUEST['SEARCH']).'/i';
  863. if (preg_match($MYREQUEST['SEARCH'], 'test') === false) {
  864. echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
  865. break;
  866. }
  867. }
  868. echo
  869. '<div class="info"><table cellspacing=0><tbody>',
  870. '<tr>',
  871. '<th>',sortheader('S',$fieldheading, "&OB=".$MYREQUEST['OB']),'</th>',
  872. '<th>',sortheader('H','Hits', "&OB=".$MYREQUEST['OB']),'</th>',
  873. '<th>',sortheader('Z','Size', "&OB=".$MYREQUEST['OB']),'</th>',
  874. '<th>',sortheader('A','Last accessed',"&OB=".$MYREQUEST['OB']),'</th>',
  875. '<th>',sortheader('M','Last modified',"&OB=".$MYREQUEST['OB']),'</th>',
  876. '<th>',sortheader('C','Created at', "&OB=".$MYREQUEST['OB']),'</th>';
  877. if($fieldname=='info') {
  878. $cols+=2;
  879. echo '<th>',sortheader('T','Timeout',"&OB=".$MYREQUEST['OB']),'</th>';
  880. }
  881. echo '<th>',sortheader('D','Deleted at',"&OB=".$MYREQUEST['OB']),'</th></tr>';
  882. // builds list with alpha numeric sortable keys
  883. //
  884. $list = array();
  885. foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
  886. switch($MYREQUEST['SORT1']) {
  887. case 'A': $k=sprintf('%015d-',$entry['access_time']); break;
  888. case 'H': $k=sprintf('%015d-',$entry['num_hits']); break;
  889. case 'Z': $k=sprintf('%015d-',$entry['mem_size']); break;
  890. case 'M': $k=sprintf('%015d-',$entry['mtime']); break;
  891. case 'C': $k=sprintf('%015d-',$entry['creation_time']); break;
  892. case 'T': $k=sprintf('%015d-',$entry['ttl']); break;
  893. case 'D': $k=sprintf('%015d-',$entry['deletion_time']); break;
  894. case 'S': $k=$entry["info"]; break;
  895. }
  896. if (!$AUTHENTICATED) {
  897. // hide all path entries if not logged in
  898. $list[$k.$entry[$fieldname]]=preg_replace('/^.*(\\/|\\\\)/','*hidden*/',$entry);
  899. } else {
  900. $list[$k.$entry[$fieldname]]=$entry;
  901. }
  902. }
  903. if ($list) {
  904. // sort list
  905. //
  906. switch ($MYREQUEST['SORT2']) {
  907. case "A": krsort($list); break;
  908. case "D": ksort($list); break;
  909. }
  910. // output list
  911. $i=0;
  912. foreach($list as $k => $entry) {
  913. if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
  914. $sh=md5($entry["info"]);
  915. $field_value = htmlentities(strip_tags($entry[$fieldname],''), ENT_QUOTES, 'UTF-8');
  916. echo
  917. '<tr id="key-'. $sh .'" class=tr-',$i%2,'>',
  918. "<td class=td-0><a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&SH=",$sh,"#key-". $sh ."\">",$field_value,'</a></td>',
  919. '<td class="td-n center">',$entry['num_hits'],'</td>',
  920. '<td class="td-n right">',$entry['mem_size'],'</td>',
  921. '<td class="td-n center">',date(DATE_FORMAT,$entry['access_time']),'</td>',
  922. '<td class="td-n center">',date(DATE_FORMAT,$entry['mtime']),'</td>',
  923. '<td class="td-n center">',date(DATE_FORMAT,$entry['creation_time']),'</td>';
  924. if($fieldname=='info') {
  925. if($entry['ttl'])
  926. echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
  927. else
  928. echo '<td class="td-n center">None</td>';
  929. }
  930. if ($entry['deletion_time']) {
  931. echo '<td class="td-last center">', date(DATE_FORMAT,$entry['deletion_time']), '</td>';
  932. } else if ($MYREQUEST['OB'] == OB_USER_CACHE) {
  933. echo '<td class="td-last center">';
  934. echo '[<a href="', $MY_SELF, '&OB=', $MYREQUEST['OB'], '&DU=', urlencode($entry[$fieldkey]), '">Delete Now</a>]';
  935. echo '</td>';
  936. } else {
  937. echo '<td class="td-last center"> &nbsp; </td>';
  938. }
  939. echo '</tr>';
  940. if ($sh == $MYREQUEST["SH"]) {
  941. echo '<tr>';
  942. echo '<td colspan="7"><pre>'.htmlentities(print_r(apcu_fetch($entry['info']), 1)).'</pre></td>';
  943. echo '</tr>';
  944. }
  945. $i++;
  946. if ($i == $MYREQUEST['COUNT'])
  947. break;
  948. }
  949. }
  950. } else {
  951. echo '<tr class=tr-0><td class="center" colspan=',$cols,'><i>No data</i></td></tr>';
  952. }
  953. echo <<< EOB
  954. </tbody></table>
  955. EOB;
  956. if ($list && $i < count($list)) {
  957. echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
  958. }
  959. echo <<< EOB
  960. </div>
  961. EOB;
  962. break;
  963. // -----------------------------------------------
  964. // Version check
  965. // -----------------------------------------------
  966. case OB_VERSION_CHECK:
  967. echo <<<EOB
  968. <div class="info"><h2>APCu Version Information</h2>
  969. <table cellspacing=0><tbody>
  970. <tr>
  971. <th></th>
  972. </tr>
  973. EOB;
  974. if (defined('PROXY')) {
  975. $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
  976. $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
  977. } else {
  978. $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
  979. }
  980. if (!$rss) {
  981. echo '<tr class="td-last center"><td>Unable to fetch version information.</td></tr>';
  982. } else {
  983. $apcversion = phpversion('apcu');
  984. preg_match('!<title>APCu ([0-9.]+)</title>!', $rss, $match);
  985. echo '<tr class="tr-0 center"><td>';
  986. if (version_compare($apcversion, $match[1], '>=')) {
  987. echo '<div class="ok">You are running the latest version of APCu ('.$apcversion.')</div>';
  988. $i = 3;
  989. } else {
  990. echo '<div class="failed">You are running an older version of APCu ('.$apcversion.'),
  991. newer version '.$match[1].' is available at <a href="http://pecl.php.net/package/APCu/'.$match[1].'">
  992. http://pecl.php.net/package/APCu/'.$match[1].'</a>
  993. </div>';
  994. $i = -1;
  995. }
  996. echo '</td></tr>';
  997. echo '<tr class="tr-0"><td><h3>Change Log:</h3><br/>';
  998. preg_match_all('!<(title|description)>([^<]+)</\\1>!', $rss, $match);
  999. $changelog = $match[2];
  1000. for ($j = 2; $j + 1 < count($changelog); $j += 2) {
  1001. $v = $changelog[$j];
  1002. if ($i < 0 && version_compare($apcversion, $ver, '>=')) {
  1003. break;
  1004. } else if (!$i--) {
  1005. break;
  1006. }
  1007. list($unused, $ver) = $v;
  1008. $changes = $changelog[$j + 1];
  1009. echo "<b><a href=\"http://pecl.php.net/package/APCu/$ver\">".htmlspecialchars($v, ENT_QUOTES, 'UTF-8')."</a></b><br><blockquote>";
  1010. echo nl2br(htmlspecialchars($changes, ENT_QUOTES, 'UTF-8'))."</blockquote>";
  1011. }
  1012. echo '</td></tr>';
  1013. }
  1014. echo <<< EOB
  1015. </tbody></table>
  1016. </div>
  1017. EOB;
  1018. break;
  1019. }
  1020. echo <<< EOB
  1021. </div>
  1022. EOB;
  1023. ?>
  1024. <!-- <?php echo "\nBased on APCGUI By R.Becker\n$VERSION\n"?> -->
  1025. </body>
  1026. </html>