apc.php 45 KB

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