prod_check.apc.inc 46 KB

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