apc.php 42 KB

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