Accueil de Gladir.com Notes légales de Gladir.com Flux RSS des nouvelles du site Gladir.com - Langage de programmation - PHP - Références des codes sources - apc.php Section du logiciel DOS «MonsterBook» Inventaire de la bibliothèque de Gladir.com Entrée administrateur


Description

Cette bibliothèque contient la panneau de contrôle «APC» disponible sur «http://pecl.php.net/package/apc».


Licence

Voici les informations de licence (N.B.: Ce site ne possède aucun droit d'auteur sur ce code source et se réfère plutôt sur celle fournit par son auteur) :

--------------------------------------------------------------------
The PHP License, version 3.01
Copyright (c) 1999 - 2011 The PHP Group. All rights reserved.
--------------------------------------------------------------------

Redistribution and use in source and binary forms, with or without
modification, is permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The name "PHP" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact group@php.net.

4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"

5. The PHP Group may publish revised and/or new versions of the
license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the terms
of that version. You may also choose to use such covered code
under the terms of any subsequent version of the license
published by the PHP Group. No one other than the PHP Group has
the right to modify the terms applicable to covered code created
under this License.

6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes PHP software, freely available from
<http://www.php.net/software/>".

THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------

This software consists of voluntary contributions made by many
individuals on behalf of the PHP Group.

The PHP Group can be contacted via Email at group@php.net.

For more information on the PHP Group and the PHP project,
please see <http://www.php.net>.

PHP includes the Zend Engine, freely available at
<http://www.zend.com>.


Code source

Voici le code source :

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


Remarque

  • L'utilisation de code source réclame l'installation du module d'extension APC destiné au PHP.



Dernière mise à jour: Dimanche, le 16 février 2014