Changeset 281

Show
Ignore:
Timestamp:
10/26/06 22:35:04 (2 years ago)
Author:
bart
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/AUTHORS

    r206 r281  
    1313Aidan Lister <aidan [ett] php [dutt] net> - The PHP_Highlight.php script 
    1414 
     15Contributors: 
     16Thomas Love <tomlove@gmail.com> - The new control panel 
     17 
    1518eAccelerator is based on Turck MMCache, written by 
    1619  Dmitry Stogov <dstogov at users.sourceforge.net> 
  • eaccelerator/trunk/ChangeLog

    r279 r281  
    44          versions were encoded, this way file cache isn't removed when using 
    55          svn snapshots or rc releases. 
     6        * Fix a compile warning when using filename hashing instead of inode  
     7          hashing. 
     8        * Optimize a part of the inode hashing function. 
     9        * Remove a conditional compile for very old php versions in the filename 
     10          hashing function. 
     11        * Included the new control center written by Thomas Love. It rocks! 
    612 
    7132006-10-19  Hans Rakers <hans at parse dot nl> 
  • eaccelerator/trunk/control.php

    r278 r281  
    11<?php  
    22/* 
    3    +----------------------------------------------------------------------+ 
    4    | eAccelerator control panel                                           | 
    5    +----------------------------------------------------------------------+ 
    6    | Copyright (c) 2004-2006 eAccelerator                                                                 | 
    7    | http://eaccelerator.net                                                                                      | 
    8    +----------------------------------------------------------------------+ 
    9    | This source file is subject to version 2.00 of the Zend license,     | 
    10    | that is bundled with this package in the file LICENSE, and is        | 
    11    | available through the world-wide-web at the following url:           | 
    12    | http://www.zend.com/license/2_00.txt.                                | 
    13    | If you did not receive a copy of the Zend license and are unable to  | 
    14    | obtain it through the world-wide-web, please send a note to          | 
    15    | license@zend.com so we can mail you a copy immediately.              | 
    16    +----------------------------------------------------------------------+ 
    17  
    18    $ Id: $ 
     3        +-----------------------------------------------------------------------+ 
     4        | eAccelerator control panel                                            | 
     5        +-----------------------------------------------------------------------+ 
     6        | Copyright (c) 2004-2006 eAccelerator                                  | 
     7        | http://eaccelerator.net                                               | 
     8        +-----------------------------------------------------------------------+ 
     9        | This source file is subject to version 3.0 of the PHP license,        | 
     10        | that is bundled with this package in the file LICENSE, and is         | 
     11        | available through the world-wide-web at the following url:            | 
     12        | http://www.php.net/license/3_0.txt.                                   | 
     13        | If you did not receive a copy of the PHP license and are unable to    | 
     14        | obtain it through the world-wide-web, please send a note to           | 
     15        | license@php.net so we can mail you a copy immediately.                | 
     16        +-----------------------------------------------------------------------+ 
    1917*/ 
    2018 
    21 if (!function_exists('eaccelerator_info')) { 
    22     die('eAccelerator isn\'t installed or isn\'t compiled with info support!'); 
    23 
    24  
    25 /** config **/ 
     19/*** CONFIG ***/ 
     20$auth = false;          // Set to false to disable authentication 
    2621$user = "admin"; 
    2722$pw = "eAccelerator"; 
    28 /** /config **/ 
    29  
    30 /* {{{ auth */ 
    31 if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_USER']) || 
    32         $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pw) { 
     23 
     24$npp = 50;              // Number of records per page (script / key cache listings) 
     25 
     26/*** TODO for API / reporting / this script:  
     27     + want script ttl from API 
     28     + would be cool to have init_time for scripts (time of caching) - could then get hit rates etc. 
     29     + count hits on user keys 
     30     + colon bug in eaccelerator_list_keys() 
     31     + might be better if usercache ttl was returned as absolute time even if expired 
     32*/ 
     33 
     34// Inline media 
     35if ($_GET['img']) { 
     36    $img = strtolower($_GET['img']); 
     37    $imgs['dnarr'][0] = 199; 
     38    $imgs['dnarr'][1] = 'H4sIAAAAAAAAA3P3dLOwTORlEGBoZ2BYsP3Y0t0nlu85ueHQ2U1Hzu86efnguetHL968cPPBtbuPbzx4+vTV24+fv3768u3nr9+/f//59+/f////GUbBKBgWQPEnCzMDgyCDDogDyhMMHP4MyhwyHhsWHGzmENaKOSHAyMDAKMWTI/BAkYmDTU6oQuAhY2M7m4JLgcGDh40c7HJ8BQaBBw4z8bMaaOx4sPAsK7voDZ8GAadTzEqSXLJWBgoM1gBhknrUcgMAAA=='; 
     39    $imgs['uparr'][0] = 201; 
     40    $imgs['uparr'][1] = 'H4sIAAAAAAAAA3P3dLOwTORlEGBoZ2BYsP3Y0t0nlu85ueHQ2U1Hzu86efnguetHL968cPPBtbuPbzx4+vTV24+fv3768u3nr9+/f//59+/f////GUbBKBgWQPEnCzMDgyCDDogDyhMMHIEMyhwyHhsWHGzmENaKOTFBoYWZgc/BYQVDw1EWdvGIOzsWJDAzinFHiBxIWNDMKMbv0sCR0NDMIcATofJB4RAzkxivg0OCoUNzIy9ThMuFDRqHGxisAZtUvS50AwAA'; 
     41 
     42    if (!$imgs[$img] || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false)  
     43        exit(); 
     44 
     45    header("Expires: ".gmdate("D, d M Y H:i:s", time()+(86400*30))." GMT"); 
     46    header("Last-Modified: ".gmdate("D, d M Y H:i:s", time())." GMT"); 
     47    header('Accept-Ranges: bytes'); 
     48    header('Content-Length: '.$imgs[$img][0]); 
     49    header('Content-Type: image/gif'); 
     50    header('Content-Encoding: gzip'); 
     51 
     52    echo base64_decode($imgs[$img][1]); 
     53    exit(); 
     54
     55 
     56// Authenticate before proceeding 
     57if ($auth && ($_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pw)) { 
    3358    header('WWW-Authenticate: Basic realm="eAccelerator control panel"'); 
    3459    header('HTTP/1.0 401 Unauthorized'); 
    3560    exit; 
    3661}  
    37 /* }}} */ 
    38  
    39 /* {{{ process any commands */ 
     62 
     63$sec = (int)$_GET['sec']; 
     64 
     65// No-cache headers 
     66header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
     67header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
     68header("Cache-Control: no-store, no-cache, must-revalidate"); 
     69header("Cache-Control: post-check=0, pre-check=0", false); 
     70header("Pragma: no-cache"); 
     71 
     72function print_footer() { 
     73    global $info; 
     74?> 
     75</div> 
     76<div class="footer"> 
     77<?php 
     78if (is_array($info)) { 
     79?> 
     80<br/><br/> 
     81    <hr style="width:500px; color: #cdcdcd" noshade="noshade" size="1" /> 
     82    <strong>Created by the eAccelerator team &ndash; <a href="http://eaccelerator.net">http://eaccelerator.net</a></strong><br /><br /> 
     83    eAccelerator <?php echo $info['version']; ?> [shm:<?php echo $info['shm_type']?> sem:<?php echo $info['sem_type']; ?>]<br /> 
     84    PHP <?php echo phpversion();?> [ZE <?php echo zend_version(); ?>]<br /> 
     85    Using <?php echo php_sapi_name();?> on <?php echo php_uname(); ?><br /> 
     86<?php 
     87
     88?> 
     89</div> 
     90</body> 
     91</html> 
     92<?php 
     93
     94 
     95if (!function_exists('eaccelerator_info')) { 
     96    die('eAccelerator isn\'t installed or isn\'t compiled with info support!'); 
     97
     98 
     99// formats sizes 
     100function format_size ($x) { 
     101    $a = array('bytes', 'kb', 'mb', 'gb'); 
     102    $i = 0; 
     103    while ($x >= 1024) { 
     104        $i++; 
     105        $x = $x / 1024; 
     106    } 
     107    return number_format($x, ($i > 0)?2:0, '.', ',').' '.$a[$i]; 
     108
     109 
     110// Generates a simple & colourful horizontal bar graph. $x:$y is used:free 
     111function space_graph ($x, $y) { 
     112    $colr = 183; $colg = 225; $colb = 149;      // #B7E195 
     113 
     114    $colr = base_convert($colr + floor(($x/$y)*(50+exp($x*3/$y))), 10, 16); 
     115    $colg = base_convert($colg - floor(($x/$y)*(100+exp($x*4/$y))), 10, 16); 
     116    $colb = base_convert($colb - floor(($x/$y)*(70+exp($x*4/$y))), 10, 16); 
     117 
     118    $s = '<table class="hgraph"><tr>'; 
     119    $s .= '<td class="hgraph_pri" style="width:'.floor(($x/$y)*100).'%">&nbsp;</td>'; 
     120    $s .= '<td class="hgraph_sec" style="background-color: #'.$colr.$colg.$colb.'; width:'.ceil(100 - ($x/$y)*100).'%">&nbsp;</td></tr></table>'; 
     121    return $s; 
     122
     123 
     124// Messy algorithm to generate neat page selectors 
     125function pageselstr ($pg, $pgs) { 
     126    $pg += 1; 
     127    $st = max(1, $pg - 2) - max(0, 2 - ($pgs - $pg)); 
     128    $nd = $pg + 2 + max(0, 3 - $pg); 
     129    $d = $st - 1 - 1; 
     130    if (abs($nd - $pg) > 2) $sp[] = $nd - 2; 
     131    if (abs($pg - $st) > 2) $sp[] = $st + 2; 
     132    if (($d-2)/3 >= 2) { 
     133        $sp[] = (ceil($d/3)+1); 
     134        $sp[] = (ceil($d/3)*2+1); 
     135    } 
     136    elseif (($d-1)/2 > 0) $sp[] = (ceil($d/2)+1); 
     137    $d = $pgs - $nd - 1; 
     138    if (($d-2)/3 >= 2) { 
     139        $sp[] = (ceil($d/3)+$nd); 
     140        $sp[] = (ceil($d/3)*2+$nd); 
     141    } 
     142    elseif (($d-1)/2 > 0) $sp[] = (ceil($d/2)+$nd); 
     143    $sp[] = $st;$sp[] = $nd;$sp[] = $pg;$sp[] = 1;$sp[] = $pgs; 
     144    $lp = 1; 
     145    $pgstr = 'Page: '; 
     146    if ($pgs < 1) $pgstr .= '-'; 
     147    for ($i = 1; $i <= $pgs; $i++) { 
     148        if (in_array($i, $sp)) { 
     149            if ($i - $lp <= 2 && $i > 2 && !in_array($i-1, $sp)) $pgstr .= '<a href="'.$_SERVER['PHP_SELF'].'?'.qstring_update(array('pg' => $i-2)).'">'.($i-1).'</a> '; 
     150            if ($i - $lp > 2) $pgstr .= '..'; 
     151            if ($i == $pg) $pgstr .= ' ['.$i.'] '; 
     152            else { 
     153                $pgstr .= ' <a href="'.$_SERVER['PHP_SELF'].'?'.qstring_update(array('pg' => $i-1)).'">'.$i.'</a> '; 
     154            } 
     155            $lp = $i; 
     156        } 
     157    } 
     158    return $pgstr; 
     159
     160 
     161// Returns qstring with updated key / value pairs. 
     162function qstring_update ($arr) { 
     163    $qs = ''; 
     164    $combo = array_merge($_GET, $arr); 
     165    foreach ($combo as $a => $b) { 
     166        if ($qs) $qs .= '&'; 
     167        $qs .= urlencode($a).'='.urlencode($b); 
     168    } 
     169    return $qs; 
     170
     171 
     172// Returns standard column headers for the lists 
     173function colheadstr ($nme, $id) { 
     174    $cursrt = $_GET['ordby']; 
     175    $srtdir = $_GET['dir']; 
     176    return '<a href="'.$_SERVER['PHP_SELF'].'?'.qstring_update(array('ordby' => $id, 'dir' => ($cursrt == $id)?1-$srtdir:0)).'">'.$nme.'&nbsp;'.(($cursrt == $id)?'<img src="'.$_SERVER['PHP_SELF'].'?img='.(($srtdir)?'dnarr':'uparr').'" width="13" height="16" border="0" alt="'.(($srtdir)?'v':'^').'"/>':''); 
     177
     178 
     179// Array sorting callback function 
     180function arrsort ($a, $b) { 
     181    global $ordby, $ordbystr; 
     182    if ($ordbystr) $val = strnatcmp($a[$ordby], $b[$ordby]); 
     183    else $val = ($a[$ordby]==$b[$ordby])?0:(($a[$ordby]<$b[$ordby])?-1:1); 
     184    if ($_GET['dir']) $val = -1*$val; 
     185    return $val; 
     186
     187 
     188// Global info array 
    40189$info = eaccelerator_info(); 
    41 if (isset($_POST['caching'])) { 
    42     if ($info['cache']) { 
    43         eaccelerator_caching(false); 
    44     } else { 
    45         eaccelerator_caching(true); 
    46     } 
    47 } else if (isset($_POST['optimizer']) && function_exists('eaccelerator_optimizer')) { 
    48     if ($info['optimizer']) { 
    49         eaccelerator_optimizer(false); 
    50     } else { 
    51         eaccelerator_optimizer(true); 
    52     } 
    53 } else if (isset($_POST['clear'])) { 
    54     eaccelerator_clear(); 
    55 } else if (isset($_POST['clean'])) { 
    56     eaccelerator_clean(); 
    57 } else if (isset($_POST['purge'])) { 
    58     eaccelerator_purge(); 
    59 
    60 $info = eaccelerator_info(); 
    61 if (!is_array($info)) { 
    62         die('An error occured getting eAccelerator information, this is caused if eAccelerator isn\'t initalised properly'); 
    63 
    64 /* }}} */ 
    65  
    66 function compare($x, $y) 
    67 
    68   global $sortby; 
    69  
    70   if ( $x[$sortby] == $y[$sortby] ) 
    71     return 0; 
    72   else if ( $x[$sortby] < $y[$sortby] ) 
    73     return -1; 
    74   else 
    75     return 1; 
    76 
    77  
    78 function revcompare($x, $y) 
    79 
    80   global $sortby; 
    81  
    82   if ( $x[$sortby] == $y[$sortby] ) 
    83     return 0; 
    84   else if ( $x[$sortby] < $y[$sortby] ) 
    85     return 1; 
    86   else 
    87     return -1; 
    88 
    89     
    90 /* {{{ create_script_table */ 
    91 function create_script_table($list) { 
    92   global $sortby; 
    93  
    94   if (isset($_GET['order']) && ($_GET['order'] == "asc" || $_GET['order'] =="desc")) { 
    95     $order = $_GET['order']; 
    96   } else { 
    97     $order = "asc"; 
    98   } 
    99    
    100   if (isset($_GET['sort'])) { 
    101     switch ($_GET['sort']) { 
    102       case "mtime": 
    103       case "size": 
    104       case "reloads": 
    105       case "hits": 
    106         $sortby = $_GET['sort']; 
    107         ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare')); 
    108         break; 
    109       default: 
    110         $sortby = "file"; 
    111         ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare')); 
    112     } 
    113   } 
    114  
    115 ?> 
    116     <table> 
    117         <tr> 
    118             <th><a href="<?php echo $_SERVER['PHP_SELF']?>?sort=file&order=<?php echo($order == "asc" ? "desc" : "asc")?>">Filename</a>&nbsp;<?php if($sortby == "file") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th> 
    119             <th><a href="<?php echo $_SERVER['PHP_SELF']?>?sort=mtime&order=<?php echo ($order == "asc" ? "desc" : "asc")?>">MTime</a>&nbsp;<?php if($sortby == "mtime") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th> 
    120             <th><a href="<?php echo $_SERVER['PHP_SELF']?>?sort=size&order=<?php echo ($order == "asc" ? "desc" : "asc")?>">Size</a>&nbsp;<?php if($sortby == "size") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th> 
    121             <th><a href="<?php echo $_SERVER['PHP_SELF']?>?sort=reloads&order=<?php echo ($order == "asc" ? "desc" : "asc")?>">Reloads</a>&nbsp;<?php if($sortby == "reloads") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th> 
    122             <th><a href="<?php echo $_SERVER['PHP_SELF']?>?sort=hits&order=<?php echo ($order == "asc" ? "desc" : "asc")?>">Hits</a>&nbsp;<?php if($sortby == "hits") echo ($order == "asc" ? "&darr;" : "&uarr;")?></th> 
    123         </tr> 
    124     <?php 
    125           switch ($sortby) { 
    126             case "mtime": 
    127             case "size": 
    128             case "reloads": 
    129             case "hits": 
    130               ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare')); 
    131               break; 
    132             case "file": 
    133             default: 
    134               $sortby = "file"; 
    135               ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare')); 
    136                
    137           } 
    138  
    139           foreach($list as $script) { ?> 
    140         <tr> 
    141     <?php   if (function_exists('eaccelerator_dasm_file')) { ?> 
    142             <td class="e"><a href="dasm.php?file=<?php echo $script['file']; ?>"><?php echo $script['file']; ?></a></td> 
    143     <?php   } else { ?> 
    144             <td class="e"><?php echo $script['file']; ?></td> 
    145     <?php   } ?> 
    146             <td class="vr"><?php echo date('Y-m-d H:i', $script['mtime']); ?></td> 
    147             <td class="vr"><?php echo number_format($script['size'] / 1024, 2); ?> KB</td> 
    148             <td class="vr"><?php echo $script['reloads']; ?> (<?php echo $script['usecount']; ?>)</td> 
    149             <td class="vr"><?php echo $script['hits']; ?></td> 
    150         </tr> 
    151     <?php } ?> 
    152     </table> 
    153 <?php  
    154 
    155 /* }}} */ 
    156  
    157 /* {{{ create_key_table */ 
    158 function create_key_table($list) { 
    159 ?> 
    160     <table class="key"> 
    161         <tr> 
    162             <th>Name</th> 
    163             <th>Created</th> 
    164             <th>Size</th> 
    165             <th>ttl</th> 
    166         </tr> 
    167 <?php 
    168     foreach($list as $key) { 
    169 ?> 
    170         <tr> 
    171             <td class="e"><?php echo $key['name']; ?></td> 
    172             <td class="vr"><?php echo date('Y-m-d H:i', $key['created']); ?></td> 
    173             <td class="vr"><?php echo number_format($key['size']/1024, 3); ?>KB</td> 
    174             <td class="vr"><?php  
    175                 if ($key['ttl'] == -1) { 
    176                     echo 'expired'; 
    177                 } elseif ($key['ttl'] == 0) { 
    178                     echo 'none'; 
    179                 } else { 
    180                     echo date('Y-m-d H:i', $key['ttl']); 
    181                 } 
    182             ?></td> 
    183         </tr> 
    184 <?php 
    185     } 
    186 ?> 
    187     </table> 
    188 <?php 
    189 
    190 /* }}} */ 
    191  
    192 /* {{{ print_header */ 
    193 function print_header() { ?> 
    194 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
     190 
     191?> 
     192<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    195193<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
    196194<head> 
     
    201199 
    202200    <style type="text/css" media="all"> 
    203         body {background-color: #ffffff; color: #000000;} 
    204         body, td, th, h1, h2 {font-family: sans-serif;} 
    205         pre {margin: 0px; font-family: monospace;} 
    206         a:link {color: #000099; text-decoration: none} 
    207         a:hover {text-decoration: underline;} 
    208         table {border-collapse: collapse; width: 800px;} 
    209         .center {text-align: center;} 
    210         .center table { margin-left: auto; margin-right: auto; text-align: left;} 
    211         .center th { text-align: center !important; } 
    212         td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;} 
    213         h1 {font-size: 150%;} 
    214         h2 {font-size: 125%;} 
    215         .p {text-align: left;} 
    216         .e {background-color: #ccccff; font-weight: bold; color: #000000;} 
    217         .h,th {background-color: #9999cc; font-weight: bold; color: #000000;} 
    218         .v,td {background-color: #cccccc; color: #000000;} 
    219         .vr{background-color: #cccccc; text-align: right; color: #000000; white-space: nowrap;} 
    220         img {float: right; border: 0px;} 
    221         hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;} 
    222         input {width: 150px} 
    223         h1 {width: 800px;  border: 1px solid #000000; margin-left: auto; margin-right: auto; background-color: #9999cc;} 
     201        body {background-color: #ffffff; color: #000000;margin: 0px;} 
     202        body, td {font-family: Tahoma, sans-serif;font-size: 12pt;} 
     203 
     204        a:link {color: #ff0000; text-decoration: none;} 
     205        a:visited {color: #ff0000; text-decoration: none;} 
     206        a:active {color: #aa0000; text-decoration: none;} 
     207        a:hover {color: #aa0000; text-decoration: none;} 
     208         
     209        .head1 {background-color: #A9CFDD; width: 100%; font-size: 32px; color: #ffffff;padding-top: 20px;font-family: Tahoma, sans-serif;} 
     210        .head1_item {padding-left: 15px;} 
     211        .head2 {background-color: #62ADC2; width: 100%; font-size: 18px; color: #ffffff;text-align: right; font-family: Tahoma, sans-serif;border-top: #ffffff 2px solid;} 
     212        .head2 a:link {color: #ffffff;} 
     213        .head2 a:visited {color: #ffffff;} 
     214        .head2 a:active {color: #ffffff;} 
     215        .head2 a:hover {color: #000000;} 
     216 
     217        .menuitem {padding-left: 15px;padding-right: 15px;} 
     218        .menuitem_sel {padding-left: 15px;padding-right: 15px;background-color: #ffffff; color: #000000;} 
     219        .menuitem_hov {padding-left: 15px;padding-right: 15px;cursor:pointer;color: #000000;} 
     220        .mnbody {padding:15px; padding-top: 30px; margin-right: auto; margin-left: auto; text-align: center;bottom: 60px;} 
     221 
     222        .mnbody table {border-collapse: collapse; margin-right: auto; margin-left: auto;} 
     223         
     224        td {padding: 3px 10px 3px 10px; border: #ffffff 2px solid;vertical-align:top} 
     225        .el {text-align: left;background-color: #e1eff8;} 
     226        .er {text-align: right;background-color: #e1eff8;} 
     227        .ec {text-align: center;background-color: #e1eff8;} 
     228 
     229        .fl {text-align: left;background-color: #efefef;} 
     230        .fr {text-align: right;background-color: #efefef;} 
     231 
     232        .h {text-align: center; font-weight: bold;} 
     233        .h a:link {color: #000000;} 
     234        .h a:visited {color: #000000;} 
     235        .h a:active {color: #ababab;} 
     236        .h a:hover {color: #ababab;} 
     237 
     238        .hgraph {width:100%;} 
     239        .hgraph td {border: 0px;padding: 0px;} 
     240        .hgraph_pri {background-color: #62ADC2;} 
     241        .hgraph_sec {} 
     242         
     243         
     244        .footer {width: 100%;text-align: center;font-size: 9pt;color: #ababab;} 
     245        .footer a:link {color: #ababab;} 
     246        .footer a:visited {color: #ababab;} 
     247        .footer a:active {color: #000000;} 
     248        .footer a:hover {color: #000000;} 
     249         
     250        small {font-size: 10pt;} 
     251        .s {color: #676767;} 
     252 
    224253    </style> 
     254     
     255    <script type="text/javascript"> 
     256      function menusel(i) { 
     257        if (i.className == "menuitem_hov") i.className = "menuitem"; 
     258        else if (i.className == "menuitem") i.className = "menuitem_hov"; 
     259      } 
     260      function gosec(i) { 
     261        document.location = "<?php echo $_SERVER['PHP_SELF']?>?sec="+i; 
     262      } 
     263    </script> 
     264     
    225265</head> 
    226 <?php  
    227 }  
    228 /* }}} */ 
    229 ?> 
    230  
    231 <?php print_header(); ?> 
    232 <body class="center"> 
    233 <h1>eAccelerator <?php echo $info['version']; ?> control panel</h1> 
    234  
    235 <!-- {{{ information --> 
    236 <h2>Information</h2> 
     266 
     267<body> 
     268<div class="head1"><span class="head1_item">eAccelerator control panel</span></div> 
     269<div class="head2"> 
     270<?php 
     271$items = array(0 => 'Status', 1 => 'Script Cache', 2 => 'User Cache'); 
     272foreach ($items as $i => $item) { 
     273    echo '<span class="menuitem'.(($sec == $i)?'_sel':'').'" onmouseover="menusel(this)" onmouseout="menusel(this)" onclick="gosec('.$i.')">'.(($sec != $i)?'<a href="'.$_SERVER['PHP_SELF'].'?sec='.$i.'">'.$item.'</a>':$item).'</span>'; 
     274}   
     275?> 
     276</div> 
     277<div class="mnbody"> 
     278<?php 
     279switch ($sec) { 
     280    default: 
     281    case 0: 
     282        /******************************     STATUS / CONTROL     ******************************/ 
     283 
     284        if (isset($_POST['cachingoff'])) eaccelerator_caching(false); 
     285        if (isset($_POST['cachingon'])) eaccelerator_caching(true); 
     286 
     287        if (isset($_POST['optoff']) && function_exists('eaccelerator_optimizer')) eaccelerator_optimizer(false); 
     288        if (isset($_POST['opton']) && function_exists('eaccelerator_optimizer')) eaccelerator_optimizer(true); 
     289 
     290        if (isset($_POST['clear'])) eaccelerator_clear(); 
     291        if (isset($_POST['clean'])) eaccelerator_clean(); 
     292        if (isset($_POST['purge'])) eaccelerator_purge(); 
     293 
     294        $info = eaccelerator_info(); 
     295 
     296?> 
    237297<table> 
    238 <tr> 
    239     <td class="e">Caching enabled</td>  
    240     <td><?php echo $info['cache'] ? 'yes':'no' ?></td> 
    241 </tr> 
    242 <tr> 
    243     <td class="e">Optimizer enabled</td> 
    244     <td><?php echo $info['optimizer'] ? 'yes':'no' ?></td> 
    245 </tr> 
    246 <tr> 
    247     <td class="e">Memory usage</td> 
    248     <td><?php echo number_format(100 * $info['memoryAllocated'] / $info['memorySize'], 2); ?>%  
    249         (<?php echo number_format($info['memoryAllocated'] / (1024*1024), 2); ?>MB/ 
    250         <?php echo number_format($info['memorySize'] / (1024*1024), 2); ?>MB)</td> 
    251 </tr> 
    252 <tr> 
    253     <td class="e">Free memory</td> 
    254     <td><?php echo number_format($info['memoryAvailable'] / (1024*1024), 2); ?>MB</td> 
    255 </tr> 
    256 <tr> 
    257     <td class="e">Cached scripts</td> 
    258     <td><?php echo $info['cachedScripts']; ?></td> 
    259 </tr> 
    260 <tr> 
    261     <td class="e">Removed scripts</td>  
    262     <td><?php echo $info['removedScripts']; ?></td> 
    263 </tr> 
    264 <tr> 
    265     <td class="e">Cached keys</td> 
    266     <td><?php echo $info['cachedKeys']; ?></td> 
    267 </tr> 
    268 </table> 
    269 <!-- }}} --> 
    270  
    271 <!-- {{{ control --> 
    272 <h2>Actions</h2> 
    273 <form name="ea_control" method="post"> 
    274     <table> 
    275         <tr> 
    276             <td class="e">Caching</td> 
    277             <td><input type="submit" name="caching" value="<?php echo $info['cache']?'disable':'enable'; ?>" /></td> 
    278         </tr> 
    279         <tr> 
    280             <td class="e">Optimizer</td> 
    281             <td><input type="submit" name="optimizer" value="<?php echo $info['optimizer']?'disable':'enable'; ?>" /></td> 
    282         </tr> 
    283         <tr> 
    284             <td class="e">Clear cache</td> 
    285             <td><input type="submit" name="clear" value="clear" title="remove all unused scripts and data from shared memory and disk cache" /></td> 
    286         </tr> 
    287         <tr> 
    288             <td class="e">Clean cache</td> 
    289             <td><input type="submit" name="clean" value="clean" title=" remove all expired scripts and data from shared memory and disk cache" /></td> 
    290         </tr> 
    291         <tr> 
    292             <td class="e">Purge cache</td> 
    293             <td><input type="submit" name="purge" value="purge" title="remove all 'removed' scripts from shared memory" /></td> 
    294         </tr> 
    295     </table> 
     298<tr><td> 
     299 
     300<form action="<?php echo $_SERVER['PHP_SELF']?>?sec=0" method="post"> 
     301<table> 
     302<tr> 
     303    <td class="h" colspan="2">Usage statistics</td> 
     304</tr> 
     305<tr> 
     306    <td class="er">Caching enabled</td>  
     307    <td class="fl"><?php echo $info['cache'] ? '<span style="color:green"><b>yes</b></span>&nbsp;&nbsp;&nbsp;<input type="submit" name="cachingoff" value=" Disable "/>':'<span style="color:red"><b>no</b></span>&nbsp;&nbsp;&nbsp;<input type="submit" name="cachingon" value=" Enable "/>' ?></td> 
     308</tr> 
     309<tr> 
     310    <td class="er">Optimizer enabled</td> 
     311    <td class="fl"><?php echo $info['optimizer'] ? '<span style="color:green"><b>yes</b></span>&nbsp;&nbsp;&nbsp;<input type="submit" name="optoff" value=" Disable "/>':'<span style="color:red"><b>no</b></span>&nbsp;&nbsp;&nbsp;<input type="submit" name="opton" value=" Enable "/>' ?></td> 
     312</tr> 
     313<tr> 
     314    <td class="er">Total memory</td> 
     315    <td class="fl"><?php echo format_size($info['memorySize']); ?></td> 
     316</tr> 
     317<tr> 
     318    <td class="er">Memory in use</td> 
     319    <td class="fl"><?php echo format_size($info['memoryAllocated']).' ('.number_format(100 * $info['memoryAllocated'] / max(1, $info['memorySize']), 0).'%)';?></td> 
     320</tr> 
     321<tr> 
     322    <td class="er" colspan="2"><?php echo space_graph($info['memoryAllocated'], $info['memorySize']);?></td> 
     323</tr> 
     324<tr> 
     325    <td class="er">Free memory</td> 
     326    <td class="fl"><?php echo format_size($info['memoryAvailable'])?></td> 
     327</tr> 
     328<tr> 
     329    <td class="er">Cached scripts</td> 
     330    <td class="fl"><?php echo number_format($info['cachedScripts']); ?></td> 
     331</tr> 
     332<tr> 
     333    <td class="er">Removed scripts</td>  
     334    <td class="fl"><?php echo number_format($info['removedScripts']); ?></td> 
     335</tr> 
     336<tr> 
     337    <td class="er">Cached keys</td> 
     338    <td class="fl"><?php echo number_format($info['cachedKeys']); ?></td> 
     339</tr> 
     340</table> 
    296341</form> 
    297 <!-- }}} --> 
    298  
    299 <h2>Cached scripts</h2> 
    300 <?php create_script_table(eaccelerator_cached_scripts()); ?> 
    301  
    302 <h2>Removed scripts</h2> 
    303 <?php create_script_table(eaccelerator_removed_scripts()); ?> 
    304  
    305 <?php 
    306 if (function_exists('eaccelerator_get')) { 
    307     echo "<h2>Cached keys</h2>"; 
    308     create_key_table(eaccelerator_list_keys()); 
    309 
    310 ?> 
    311  
    312 <!-- {{{ footer --> 
    313 <br /><br /> 
     342 
     343</td><td> 
     344 
    314345<table> 
    315     <tr><td class="center"> 
    316     <a href="http://eaccelerator.net"><img src="?=<?php echo $info['logo']; ?>" alt="eA logo" /></a> 
    317     <strong>Created by the eAccelerator team, <a href="http://eaccelerator.net">http://eaccelerator.net</a></strong><br /><br /> 
    318     <nobr>eAccelerator <?php echo $info['version']; ?> [shm:<?php echo $info['shm_type']?> sem:<?php echo $info['sem_type']; ?>]</nobr><br /> 
    319     <nobr>PHP <?php echo phpversion();?> [ZE <?php echo zend_version(); ?>]</nobr><br /> 
    320     <nobr>Using <?php echo php_sapi_name();?> on <?php echo php_uname(); ?></nobr><br /> 
    321     </td></tr> 
    322 </table> 
    323 <!-- }}} --> 
    324 </body> 
    325 </html> 
    326  
    327 <?php 
    328  
    329 /* 
    330  * Local variables: 
    331  * tab-width: 4 
    332  * c-basic-offset: 4 
    333  * End: 
    334  * vim600: noet sw=4 ts=4 fdm=marker 
    335  * vim<600: noet sw=4 ts=4 
    336  */ 
    337  
    338 ?> 
     346<tr> 
     347    <td class="h" colspan="2">Build information</td> 
     348</tr> 
     349<tr> 
     350    <td class="er">eAccelerator version</td>  
     351    <td class="fl"><?php echo $info['version']; ?></td> 
     352</tr> 
     353<tr> 
     354    <td class="er">Shared memory type</td>  
     355    <td class="fl"><?php echo $info['shm_type']; ?></td> 
     356</tr> 
     357<tr> 
     358    <td class="er">Semaphore type</td>  
     359    <td class="fl"><?php echo $info['sem_type']; ?></td> 
     360</tr> 
     361</table> 
     362 
     363</td></tr> 
     364</table> 
     365 
     366<br/><br/> 
     367 
     368<form action="<?php echo $_SERVER['PHP_SELF']?>?sec=0" method="post"> 
     369<table> 
     370<tr> 
     371    <td class="h" colspan="2">Maintenance</td> 
     372</tr> 
     373<tr> 
     374    <td class="ec"><input type="submit" name="clear" value=" Clear cache "/></td>  
     375    <td class="fl">Removed all scripts and data from shared memory and / or disk.</td> 
     376</tr> 
     377<tr> 
     378    <td class="ec"><input type="submit" name="clean" value=" Delete expired "/></td>  
     379    <td class="fl">Removed all expired scripts and data from shared memory and / or disk.</td> 
     380</tr> 
     381<tr> 
     382    <td class="ec"><input type="submit" name="purge" value=" Purge cache "/></td>  
     383    <td class="fl">Delete all 'removed' scripts from shared memory.</td> 
     384</tr> 
     385</table> 
     386</form> 
     387 
     388<?php 
     389        break; 
     390    case 1: 
     391        /******************************     SCRIPT CACHE     ******************************/ 
     392     
     393        $scripts = eaccelerator_cached_scripts(); 
     394        $removed = eaccelerator_removed_scripts(); 
     395     
     396        // combine arrays 
     397        function removedmod ($val) { 
     398            $val['removed'] = true; 
     399            return $val; 
     400        } 
     401        $scripts = array_merge($scripts, array_map('removedmod', $removed)); 
     402     
     403        // search 
     404        function scriptsearch ($val) { 
     405            return preg_match('/'.preg_quote($_GET['str'], '/').'/i', $val['file']); 
     406        } 
     407        $scripts = array_filter($scripts, 'scriptsearch'); 
     408     
     409        // sort 
     410        switch ($_GET['ordby']) { 
     411            default: 
     412            case 0: $ordby = 'file'; $ordbystr = true; break; 
     413            case 1: $ordby = 'mtime'; $ordbystr = false; break; 
     414            case 2: $ordby = 'size'; $ordbystr = false; break; 
     415            case 3: $ordby = 'reloads'; $ordbystr = false; break; 
     416            case 4: $ordby = 'hits'; $ordbystr = false; break; 
     417        } 
     418        usort($scripts, 'arrsort'); 
     419  
     420        // slice 
     421        $numtot = count($scripts); 
     422 
     423        $pg = (int)$_GET['pg']; // zero-starting 
     424        $pgs = ceil($numtot/$npp); 
     425 
     426        if ($pg+1 > $pgs) $pg = $pgs-1; 
     427        if ($pg < 0) $pg = 0; 
     428 
     429        $scripts = array_slice($scripts, $pg*$npp, $npp); 
     430        $numres = count($scripts); 
     431?> 
     432<table class="center"> 
     433<tr> 
     434    <td class="h" colspan="2">Search</td> 
     435</tr> 
     436<tr> 
     437    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="get"><input type="hidden" name="sec" value="1"/> 
     438    <td class="el">Match filename:</td>  
     439    <td class="fl"><input type="text" name="str" size="40" value="<?php echo $_GET['str']?>"/>&nbsp;<input type="submit" value=" Find "/></td> 
     440    </form> 
     441</tr> 
     442</table> 
     443 
     444<br/><br/> 
     445 
     446<?php 
     447        if (count($scripts) == 0)  
     448            echo '<div class="center"><i>No scripts found</i></div>'; 
     449        else { 
     450?> 
     451<table class="center"> 
     452<tr> 
     453    <td colspan="1" style="text-align: left">Showing <?php echo $pg*$npp+1?> &ndash; <?php echo $pg*$npp+min($npp, $numres)?> of <?php echo $numtot?></td> 
     454    <td colspan="4" style="text-align: right;"><small><?php echo pageselstr($pg, $pgs)?></small></td> 
     455</tr> 
     456<tr> 
     457    <td class="h"><?php echo colheadstr('File', 0)?></td> 
     458    <td class="h"><?php echo colheadstr('Last Modified', 1)?></td> 
     459    <td class="h"><?php echo colheadstr('Size', 2)?></td> 
     460    <td class="h"><?php echo colheadstr('Reloads', 3)?></td> 
     461    <td class="h"><?php echo colheadstr('Hits', 4)?></td> 
     462</tr> 
     463<?php 
     464            for ($i = 0; $i < $numres; $i++) { 
     465?> 
     466<tr> 
     467    <td class="el"><small><?php echo (($scripts[$i]['removed'])?'<span class="s">':'').$scripts[$i]['file'].(($scripts[$i]['removed'])?'</span>':'')?></small></td> 
     468    <td class="fl"><small><?php echo date('Y-m-d H:i:s', $scripts[$i]['mtime'])?></small></td> 
     469    <td class="fr"><small><?php echo format_size($scripts[$i]['size'])?></small></td> 
     470    <td class="fr"><small><?php echo $scripts[$i]['reloads']?> (<?php echo $scripts[$i]['usecount']?>)</small></td> 
     471    <td class="fr"><small><?php echo number_format($scripts[$i]['hits'])?></small></td> 
     472</tr> 
     473<?php 
     474      } 
     475?> 
     476<tr> 
     477    <td colspan="1" style="text-align: left">&nbsp;</td> 
     478    <td colspan="4" style="text-align: right;"><small><?php echo pageselstr($pg, ceil($numtot/$npp))?></small></td> 
     479</tr> 
     480</table> 
     481<?php 
     482            } 
     483            break; 
     484        case 2: 
     485        /******************************     USER CACHE     ******************************/ 
     486 
     487        $userkeys = eaccelerator_list_keys(); 
     488 
     489        // ** work around colon bug ** 
     490        function colonbug ($val) { 
     491            if (substr($val['name'], 0, 1) == ':')  
     492                $val['name'] = substr($val['name'], 1); 
     493            return $val; 
     494        } 
     495        $userkeys = array_map('colonbug', $userkeys); 
     496 
     497        // search 
     498        function usersearch ($val) { 
     499            return preg_match('/'.preg_quote($_GET['str'], '/').'/i', $val['name']); 
     500        } 
     501        $userkeys = array_filter($userkeys, 'usersearch'); 
     502     
     503        // sort 
     504        switch ($_GET['ordby']) { 
     505            default: 
     506            case 0: $ordby = 'name'; $ordbystr = true; break; 
     507            case 1: $ordby = 'created'; $ordbystr = false; break; 
     508            case 2: $ordby = 'size'; $ordbystr = false; break; 
     509            case 3: $ordby = 'ttl'; $ordbystr = false; break; 
     510        } 
     511        usort($userkeys, 'arrsort'); 
     512  
     513        // slice 
     514        $numtot = count($userkeys); 
     515 
     516        $pg = (int)$_GET['pg']; // zero-starting 
     517        $pgs = ceil($numtot/$npp); 
     518 
     519        if ($pg+1 > $pgs) $pg = $pgs-1; 
     520        if ($pg < 0) $pg = 0; 
     521 
     522        $userkeys = array_slice($userkeys, $pg*$npp, $npp); 
     523        $numres = count($userkeys); 
     524?> 
     525<table class="center"> 
     526<tr> 
     527    <td class="h" colspan="2">Search</td> 
     528</tr> 
     529<tr> 
     530    <form name="srch" action="<?php echo $_SERVER['PHP_SELF']?>" method="get"><input type="hidden" name="sec" value="2"/> 
     531    <td class="el">Match key name:</td>  
     532    <td class="fl"><input type="text" name="str" size="40" value="<?php echo $_GET['str']?>"/>&nbsp;<input type="submit" value=" Find "/></td> 
     533    </form> 
     534</tr> 
     535</table> 
     536 
     537<br/><br/> 
     538 
     539<?php 
     540        if (count($userkeys) == 0)  
     541            echo '<div class="center"><i>No keys found</i></div>'; 
     542        else { 
     543?> 
     544<table class="center"> 
     545<tr> 
     546    <td colspan="1" style="text-align: left">Showing <?php echo $pg*$npp+1?> &ndash; <?php echo $pg*$npp+min($npp, $numres)?> of <?php echo $numtot?></td> 
     547    <td colspan="4" style="text-align: right;"><small><?php echo pageselstr($pg, $pgs)?></small></td> 
     548</tr> 
     549<tr> 
     550    <td class="h"><?php echo colheadstr('Key Name', 0)?></td> 
     551    <td class="h"><?php echo colheadstr('Created', 1)?></td> 
     552    <td class="h"><?php echo colheadstr('Size', 2)?></td> 
     553    <td class="h"><?php echo colheadstr('Expiry', 3)?></td> 
     554</tr> 
     555<?php 
     556            for ($i = 0; $i < $numres; $i++) { 
     557?> 
     558<tr> 
     559    <td class="el"><small><?php echo (($userkeys[$i]['ttl'] == -1)?'<span class="s">':'').$userkeys[$i]['name'].(($userkeys[$i]['ttl'] == -1)?'</span>':'')?></small></td> 
     560    <td class="fl"><small><?php echo date('Y-m-d H:i:s', $userkeys[$i]['created'])?></small></td> 
     561    <td class="fr"><small><?php echo format_size($userkeys[$i]['size'])?></small></td> 
     562    <td class="fl"><small><?php echo ($userkeys[$i]['ttl'])?(($userkeys[$i]['ttl'] > 0)?date('Y-m-d H:i:s', $userkeys[$i]['ttl']):'expired'):'never'?></small></td> 
     563</tr> 
     564<?php 
     565      } 
     566?> 
     567<tr> 
     568    <td colspan="1" style="text-align: left">&nbsp;</td> 
     569    <td colspan="4" style="text-align: right;"><small><?php echo pageselstr($pg, ceil($numtot/$npp))?></small></td> 
     570</tr> 
     571</table> 
     572<?php 
     573            } 
     574            break; 
     575    } 
     576 
     577print_footer(); 
     578?> 
  • eaccelerator/trunk/eaccelerator.c

    r280 r281  
    44   +----------------------------------------------------------------------+ 
    55   | Copyright (c) 2004 - 2006 eAccelerator                               | 
    6    | http://eaccelerator.net                                                                                                                                                                             | 
     6   | http://eaccelerator.net                                              | 
    77   +----------------------------------------------------------------------+ 
    88   | This program is free software; you can redistribute it and/or        | 
     
    132132  hv = buf->st_dev + buf->st_ino; 
    133133#else 
    134   hv = zend_get_hash_value(key, strlen(key)); 
     134  hv = zend_get_hash_value((char *)key, strlen(key)); 
    135135#endif 
    136136  slot = hv & EA_HASH_MAX; 
     
    413413  n = strlen(s); 
    414414  for (i = 1; i <= EACCELERATOR_HASH_LEVEL && n < MAXPATHLEN - 1; i++) { 
    415     s[n++] = num2hex[(ino >> (i*4)) & 0xf]; 
     415    s[n++] = num2hex[(ino >> (i << 2)) & 0xf]; // (ino / (i * 4)) 
    416416    s[n++] = '/'; 
    417417  } 
     
    439439/* Function to create a hash key when filenames are used */ 
    440440int eaccelerator_md5(char* s, const char* prefix, const char* key TSRMLS_DC) { 
    441 #if defined(PHP_MAJOR_VERSION) && defined(PHP_MINOR_VERSION) && \ 
    442     ((PHP_MAJOR_VERSION > 4) || (PHP_MAJOR_VERSION == 4 && PHP_MINOR_VERSION > 1)) 
    443441  char md5str[33]; 
    444442  PHP_MD5_CTX context; 
     
    461459  snprintf(s, MAXPATHLEN-1, "%s%s%s", s, prefix, md5str); 
    462460  return 1; 
    463 #else 
    464   zval retval; 
    465   zval md5; 
    466   zval param; 
    467   zval *params[1]; 
    468  
    469   ZVAL_STRING(&md5, "md5", 0); 
    470   INIT_ZVAL(param); 
    471   params[0] = &param; 
    472   ZVAL_STRING(params[0], (char*)key, 0); 
    473   if (call_user_function(CG(function_table), (zval**)NULL, &md5, &retval, 1, params TSRMLS_CC) == SUCCESS && 
    474       Z_TYPE(retval) == IS_STRING && Z_STRLEN(retval) == 32) { 
    475     strncpy(s, EAG(cache_dir), MAXPATHLEN-1); 
    476     strlcat(s, prefix, MAXPATHLEN); 
    477     strlcat(s, Z_STRVAL(retval), MAXPATHLEN); 
    478     zval_dtor(&retval); 
    479     return 1; 
    480   } 
    481   s[0] ='\0'; 
    482 #endif 
    483   return 0; 
    484461} 
    485462