2009-02-20 21:28:16 +01:00
< ? php
2009-02-21 00:00:00 +01:00
/* Copyright ( C ) 2007 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
2007-09-19 21:42:07 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2007-09-19 21:42:07 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2007-09-19 21:42:07 +02:00
*/
/**
2010-03-01 10:20:41 +01:00
* \file htdocs / admin / tools / eaccelerator . php
* \brief Page administration de eaccelerator
*/
2007-09-19 21:42:07 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2007-09-19 21:42:07 +02:00
$langs -> load ( " admin " );
2011-12-28 12:53:46 +01:00
if ( ! $user -> admin ) accessforbidden ();
2007-09-19 21:42:07 +02:00
2007-09-20 01:32:42 +02:00
/*
2010-03-13 22:53:44 +01:00
* View
*/
2007-09-20 01:32:42 +02:00
2007-09-19 21:42:07 +02:00
llxHeader ();
2015-01-06 17:54:36 +01:00
if ( ! function_exists ( 'eaccelerator_info' )) {
print 'eAccelerator is not installed.' ;
llxFooter ();
exit ;
2007-09-19 21:42:07 +02:00
}
$info = eaccelerator_info ();
if ( isset ( $_POST [ 'caching' ])) {
2015-01-06 17:54:36 +01:00
if ( $info [ 'cache' ]) {
eaccelerator_caching ( false );
} else {
eaccelerator_caching ( true );
}
2007-09-19 21:42:07 +02:00
} else if ( isset ( $_POST [ 'optimizer' ]) && function_exists ( 'eaccelerator_optimizer' )) {
2015-01-06 17:54:36 +01:00
if ( $info [ 'optimizer' ]) {
eaccelerator_optimizer ( false );
} else {
eaccelerator_optimizer ( true );
}
2007-09-19 21:42:07 +02:00
} else if ( isset ( $_POST [ 'clear' ])) {
2015-01-06 17:54:36 +01:00
eaccelerator_clear ();
2007-09-19 21:42:07 +02:00
} else if ( isset ( $_POST [ 'clean' ])) {
2015-01-06 17:54:36 +01:00
eaccelerator_clean ();
2007-09-19 21:42:07 +02:00
} else if ( isset ( $_POST [ 'purge' ])) {
2015-01-06 17:54:36 +01:00
eaccelerator_purge ();
2007-09-19 21:42:07 +02:00
}
$info = eaccelerator_info ();
if ( ! is_array ( $info )) {
2015-01-06 17:54:36 +01:00
dol_print_error ( '' , 'An error occured getting eAccelerator information, this is caused if eAccelerator isn\'t initalised properly' );
exit ;
2007-09-19 21:42:07 +02:00
}
2007-09-20 01:32:42 +02:00
2015-01-06 17:54:36 +01:00
/**
* Compare revisions
*
* @ param array $x Parts of version 1
* @ param array $y Parts of version 2
* @ return int - 1 if 1 < 2 , 0 if 1 = 2 , 1 if 1 > 2
*/
2007-09-19 21:42:07 +02:00
function compare ( $x , $y )
{
2015-01-06 17:54:36 +01:00
global $sortby ;
if ( $x [ $sortby ] == $y [ $sortby ] ) {
return 0 ;
} else if ( $x [ $sortby ] < $y [ $sortby ]) {
return - 1 ;
} else {
return 1 ;
}
2007-09-19 21:42:07 +02:00
}
2011-09-14 23:50:18 +02:00
/**
* Compare revisions
2011-12-12 19:50:59 +01:00
*
2015-01-06 17:54:36 +01:00
* @ param array $x Parts of version 1
* @ param array $y Parts of version 2
* @ return int 1 if 1 < 2 , 0 if 1 = 2 , - 1 if 1 > 2
2011-09-14 23:50:18 +02:00
*/
2007-09-19 21:42:07 +02:00
function revcompare ( $x , $y )
{
2015-02-19 00:01:26 +01:00
global $sortby ;
2015-01-06 17:54:36 +01:00
if ( $x [ $sortby ] == $y [ $sortby ]) {
return 0 ;
} else if ( $x [ $sortby ] < $y [ $sortby ]) {
return 1 ;
} else {
return - 1 ;
}
2007-09-19 21:42:07 +02:00
}
2009-02-20 21:28:16 +01:00
2011-09-14 23:50:18 +02:00
/**
* Output table
2011-12-12 19:50:59 +01:00
*
2015-01-06 17:54:36 +01:00
* @ param array $list Array of records
* @ return void
2011-09-14 23:50:18 +02:00
*/
2010-03-13 22:53:44 +01:00
function create_script_table ( $list )
2007-09-20 01:32:42 +02:00
{
2018-04-23 16:04:52 +02:00
global $sortby , $langs ;
2015-01-06 17:54:36 +01:00
2016-05-08 12:32:18 +02:00
if ( GETPOT ( 'order' ) == " asc " || GETPOST ( 'order' ) == " desc " ) {
$order = GETPOST ( 'order' );
2015-01-06 17:54:36 +01:00
} else {
$order = " asc " ;
}
2016-05-08 12:32:18 +02:00
if ( GETPOST ( 'order' )) {
switch ( GETPOST ( 'order' )) {
2015-01-06 17:54:36 +01:00
case " mtime " :
case " size " :
case " reloads " :
case " hits " :
2016-05-08 12:32:18 +02:00
$sortby = GETPOST ( 'sort' );
2015-01-06 17:54:36 +01:00
( $order == " asc " ? uasort ( $list , 'compare' ) : uasort ( $list , 'revcompare' ));
break ;
default :
$sortby = " file " ;
( $order == " asc " ? uasort ( $list , 'compare' ) : uasort ( $list , 'revcompare' ));
}
}
print '<table class="noborder">' ;
print '<tr>' ;
print '<th><a href="' . $_SERVER [ 'PHP_SELF' ] . '?sort=file&order=' . ( $order == " asc " ? " desc " : " asc " ) . '">' . $langs -> trans ( " Filename " ) . '</a> ' ;
if ( $sortby == " file " )
print ( $order == " asc " ? " ↓ " : " ↑ " ) . '</th>' ;
print '<th><a href="' . $_SERVER [ 'PHP_SELF' ] . '?sort=mtime&order=' . ( $order == " asc " ? " desc " : " asc " ) . '">' . $langs -> trans ( " Date " ) . '</a> ' ;
2015-02-19 00:01:26 +01:00
if ( $sortby == " mtime " )
2015-01-06 17:54:36 +01:00
print ( $order == " asc " ? " ↓ " : " ↑ " ) . '</th>' ;
print '<th><a href="' . $_SERVER [ 'PHP_SELF' ] . '?sort=size&order=' . ( $order == " asc " ? " desc " : " asc " ) . '">' . $langs -> trans ( " Size " ) . '</a> ' ;
2015-02-19 00:01:26 +01:00
if ( $sortby == " size " )
2015-01-06 17:54:36 +01:00
print ( $order == " asc " ? " ↓ " : " ↑ " ) . '</th>' ;
print '<th><a href="' . $_SERVER [ 'PHP_SELF' ] . '?sort=reloads&order=' . ( $order == " asc " ? " desc " : " asc " ) . '">' . $langs -> trans ( " Reloads " ) . '</a> ' ;
2015-02-19 00:01:26 +01:00
if ( $sortby == " reloads " )
2015-01-06 17:54:36 +01:00
print ( $order == " asc " ? " ↓ " : " ↑ " ) . '</th>' ;
print '<th><a href="' . $_SERVER [ 'PHP_SELF' ] . '?sort=hits&order=' . ( $order == " asc " ? " desc " : " asc " ) . '">' . $langs -> trans ( " Hits " ) . '</a> ' ;
2015-02-19 00:01:26 +01:00
if ( $sortby == " hits " )
2015-01-06 17:54:36 +01:00
print ( $order == " asc " ? " ↓ " : " ↑ " ) . '</th>' ;
print '</tr>' ;
switch ( $sortby ) {
case " mtime " :
case " size " :
case " reloads " :
case " hits " :
( $order == " asc " ? uasort ( $list , 'compare' ) : uasort ( $list , 'revcompare' ));
break ;
case " file " :
default :
$sortby = " file " ;
( $order == " asc " ? uasort ( $list , 'compare' ) : uasort ( $list , 'revcompare' ));
}
foreach ( $list as $script ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>' . dol_trunc ( $script [ 'file' ], 80 , 'left' ) . '</td>' ;
print '<td align="center" class="nowrap">' . dol_print_date ( $script [ 'mtime' ], 'dayhour' ) . '</td>' ;
print '<td align="right" class="nowrap">' . number_format ( $script [ 'size' ] / 1024 , 2 ) . 'KB</td>' ;
print '<td align="right" class="nowrap">' . $script [ 'reloads' ] . ' (' . $script [ 'usecount' ] . ')</td>' ;
print '<td align="right" class="nowrap">' . $script [ 'hits' ] . '</td>' ;
print '</tr>' ;
}
print '</table>' ;
2007-09-19 21:42:07 +02:00
}
2011-09-14 23:50:18 +02:00
/**
* Output table
2011-12-12 19:50:59 +01:00
*
2015-01-06 17:54:36 +01:00
* @ param array $list Array of records
* @ return void
2011-09-14 23:50:18 +02:00
*/
2007-09-20 01:32:42 +02:00
function create_key_table ( $list )
{
2018-04-23 16:04:52 +02:00
global $langs ;
2015-01-06 17:54:36 +01:00
print '<table class="noborder">' ;
print '<tr class="liste_titre">' ;
print '<th>Name</th>' ;
print '<th>Created</th>' ;
print '<th>' . $langs -> trans ( " Size " ) . '</th>' ;
print '<th>ttl</th>' ;
print '</tr>' ;
foreach ( $list as $key ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>' . dol_trunc ( $key [ 'name' ], 80 , 'left' ) . '</td>' ;
print '<td align="center" class="nowrap">' . dol_print_date ( $key [ 'created' ], 'dayhour' ) . '</td>' ;
print '<td align="right" class="nowrap">' . number_format ( $key [ 'size' ] / 1024 , 3 ) . 'KB</td>' ;
print '<td align="right" class="nowrap">' ;
if ( $key [ 'ttl' ] == - 1 ) {
print 'expired' ;
} elseif ( $key [ 'ttl' ] == 0 ) {
print 'none' ;
} else {
print dol_print_date ( $key [ 'ttl' ], 'dayhour' );
}
print '</td>' ;
print '</tr>' ;
}
print '</table>' ;
2007-09-19 21:42:07 +02:00
}
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( 'Dolibarr eAccelerator ' . $info [ 'version' ] . ' control panel' , '' , 'title_setup' );
2007-09-20 01:32:42 +02:00
2015-01-06 17:54:36 +01:00
print '<br>' ;
print '<table class="noborder">' ;
print '<tr class="liste_titre">' ;
print '<td colspan="2">Information</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Caching enabled</td>' ;
print '<td align="right">' . ( $info [ 'cache' ] ? 'yes' : 'no' ) . '</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Optimizer enabled</td>' ;
print '<td align="right">' . $info [ 'optimizer' ] ? 'yes' : 'no' . '</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Memory usage</td>' ;
print '<td align="right">' . number_format ( 100 * $info [ 'memoryAllocated' ] / $info [ 'memorySize' ], 2 ) . '%(' . number_format ( $info [ 'memoryAllocated' ] / ( 1024 * 1024 ), 2 ) . 'MB / ' . number_format ( $info [ 'memorySize' ] / ( 1024 * 1024 ), 2 ) . 'MB)</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Free memory in reserved cache</td>' ;
print '<td align="right">' . number_format ( $info [ 'memoryAvailable' ] / ( 1024 * 1024 ), 2 ) . 'MB</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Cached scripts</td>' ;
print '<td align="right">' . $info [ 'cachedScripts' ] . '</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Removed scripts</td>' ;
print '<td align="right">' . $info [ 'removedScripts' ] . '</td>' ;
print '</tr>' ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print '<td>Cached keys</td>' ;
print '<td align="right">' . ( isset ( $info [ 'cachedKeys' ]) ? $info [ 'cachedKeys' ] : '' ) . '</td>' ;
print '</tr>' ;
print '</table>' ;
2007-09-20 01:32:42 +02:00
2015-01-06 17:54:36 +01:00
$resCached = @ eaccelerator_cached_scripts (); // If success return an array
2009-05-01 13:25:14 +02:00
$resRemoved = @ eaccelerator_removed_scripts ();
2015-01-06 17:54:36 +01:00
if ( is_array ( $resCached ) || is_array ( $resRemoved )) {
print " <br> " ;
print '<form name="ea_control" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="noborder">' ;
print '<tr class="liste_titre"><td colspan="2">Actions</td></tr>' ;
if ( is_array ( $resCached )) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print " <td>Caching</td> " ;
print '<td align="right"><input type="submit" class="butAction" name="caching" value="' . ( $info [ 'cache' ] ? 'disable' : 'enable' ) . '" /></td>' ;
print " </tr> " ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print " <td>Optimizer</td> " ;
print '<td align="right"><input type="submit" class="butAction" name="optimizer" value="' . ( $info [ 'optimizer' ] ? 'disable' : 'enable' ) . '" /></td>' ;
print " </tr> " ;
}
if ( is_array ( $resRemoved )) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print " <td>Clear cache</td> " ;
print '<td align="right"><input type="submit" class="butAction" name="clear" value="clear" title="remove all unused scripts and data from shared memory and disk cache" /></td>' ;
print " </tr> " ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print " <td>Clean cache</td> " ;
print '<td align="right"><input type="submit" class="butAction" name="clean" value="clean" title=" remove all expired scripts and data from shared memory and disk cache" /></td>' ;
print " </tr> " ;
2018-04-23 16:04:52 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-06 17:54:36 +01:00
print " <td>Purge cache</td> " ;
print '<td align="right"><input type="submit" class="butAction" name="purge" value="purge" title="remove all \'removed\' scripts from shared memory" /></td>' ;
print " </tr></table></form> " ;
}
if ( is_array ( $resCached )) {
print " <br><br> " ;
print " <b>Cached scripts</b><br> " ;
create_script_table ( $resCached );
}
if ( is_array ( $resRemoved )) {
print " <br><br> " ;
print " <b>Removed scripts</b><br> " ;
create_script_table ( $resRemoved );
}
} else {
print " <br><br> " ;
print " Check in your <b>php.ini</b> that <b>eaccelerator.allowed_admin_path</b> parameter is : " ;
print " <br><br> " ;
print " <b> " . $_SERVER [ " SCRIPT_FILENAME " ] . " </b> " ;
print " <br><br> " ;
2009-05-01 12:55:09 +02:00
}
2007-09-19 21:42:07 +02:00
2015-01-06 17:54:36 +01:00
if ( function_exists ( 'eaccelerator_get' )) {
print '<br><br>' ;
print '<b>Cached keys</b><br>' ;
$res = eaccelerator_list_keys ();
create_key_table ( $res );
2007-09-19 21:42:07 +02:00
}
2010-03-16 00:54:37 +01:00
print " <br><br> " ;
2007-09-19 21:42:07 +02:00
2011-08-27 21:15:14 +02:00
llxFooter ();
2011-12-12 19:50:59 +01:00
$db -> close ();