dolibarr  7.0.0-beta
eaccelerator.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
23 require '../../main.inc.php';
24 
25 $langs->load("admin");
26 
27 if (!$user->admin) accessforbidden();
28 
29 
30 /*
31  * View
32  */
33 
34 llxHeader();
35 
36 
37 if (!function_exists('eaccelerator_info')) {
38  print 'eAccelerator is not installed.';
39  llxFooter();
40  exit;
41 }
42 
43 
44 $info = eaccelerator_info();
45 if (isset($_POST['caching'])) {
46  if ($info['cache']) {
47  eaccelerator_caching(false);
48  } else {
49  eaccelerator_caching(true);
50  }
51 } else if (isset($_POST['optimizer']) && function_exists('eaccelerator_optimizer')) {
52  if ($info['optimizer']) {
53  eaccelerator_optimizer(false);
54  } else {
55  eaccelerator_optimizer(true);
56  }
57 } else if (isset($_POST['clear'])) {
58  eaccelerator_clear();
59 } else if (isset($_POST['clean'])) {
60  eaccelerator_clean();
61 } else if (isset($_POST['purge'])) {
62  eaccelerator_purge();
63 }
64 $info = eaccelerator_info();
65 if (!is_array($info)) {
66  dol_print_error('','An error occured getting eAccelerator information, this is caused if eAccelerator isn\'t initalised properly');
67  exit;
68 }
69 
70 
78 function compare($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 
98 function revcompare($x, $y)
99 {
100  global $sortby;
101 
102  if ($x[$sortby] == $y[$sortby]) {
103  return 0;
104  } else if ($x[$sortby] < $y[$sortby]) {
105  return 1;
106  } else {
107  return -1;
108  }
109 }
110 
117 function create_script_table($list)
118 {
119  global $sortby,$bc,$langs;
120  $var=true;
121 
122  if (GETPOT('order') == "asc" || GETPOST('order') =="desc") {
123  $order = GETPOST('order');
124  } else {
125  $order = "asc";
126  }
127 
128  if (GETPOST('order')) {
129  switch (GETPOST('order')) {
130  case "mtime":
131  case "size":
132  case "reloads":
133  case "hits":
134  $sortby = GETPOST('sort');
135  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
136  break;
137  default:
138  $sortby = "file";
139  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
140  }
141  }
142 
143  print '<table class="noborder">';
144  print '<tr>';
145  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=file&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Filename").'</a>&nbsp;';
146  if($sortby == "file")
147  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
148  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=mtime&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Date").'</a>&nbsp;';
149  if($sortby == "mtime")
150  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
151  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=size&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Size").'</a>&nbsp;';
152  if($sortby == "size")
153  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
154  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=reloads&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Reloads").'</a>&nbsp;';
155  if($sortby == "reloads")
156  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
157  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=hits&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Hits").'</a>&nbsp;';
158  if($sortby == "hits")
159  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
160  print '</tr>';
161  switch ($sortby) {
162  case "mtime":
163  case "size":
164  case "reloads":
165  case "hits":
166  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
167  break;
168  case "file":
169  default:
170  $sortby = "file";
171  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
172 
173  }
174 
175  foreach($list as $script) {
176  $var = ! $var;
177  print '<tr class="oddeven">';
178  print '<td>'.dol_trunc($script['file'],80,'left').'</td>';
179  print '<td align="center" class="nowrap">'.dol_print_date($script['mtime'],'dayhour').'</td>';
180  print '<td align="right" class="nowrap">'.number_format($script['size'] / 1024, 2).'KB</td>';
181  print '<td align="right" class="nowrap">'.$script['reloads'].' ('.$script['usecount'].')</td>';
182  print '<td align="right" class="nowrap">'.$script['hits'].'</td>';
183  print '</tr>';
184  }
185  print '</table>';
186 
187 }
188 
195 function create_key_table($list)
196 {
197  global $bc,$langs;
198  $var=true;
199 
200  print '<table class="noborder">';
201  print '<tr class="liste_titre">';
202  print '<th>Name</th>';
203  print '<th>Created</th>';
204  print '<th>'.$langs->trans("Size").'</th>';
205  print '<th>ttl</th>';
206  print '</tr>';
207 
208  foreach($list as $key) {
209  $var = !$var;
210  print '<tr class="oddeven">';
211  print '<td>'.dol_trunc($key['name'],80,'left').'</td>';
212  print '<td align="center" class="nowrap">'.dol_print_date($key['created'],'dayhour').'</td>';
213  print '<td align="right" class="nowrap">'.number_format($key['size']/1024, 3).'KB</td>';
214  print '<td align="right" class="nowrap">';
215  if ($key['ttl'] == -1) {
216  print 'expired';
217  } elseif ($key['ttl'] == 0) {
218  print 'none';
219  } else {
220  print dol_print_date($key['ttl'],'dayhour');
221  }
222  print '</td>';
223  print '</tr>';
224  }
225  print '</table>';
226 }
227 
228 
229 $form=new Form($db);
230 print load_fiche_titre('Dolibarr eAccelerator '.$info['version'].' control panel','','title_setup');
231 
232 $var=true;
233 
234 print '<br>';
235 
236 
237 print '<table class="noborder">';
238 print '<tr class="liste_titre">';
239 print '<td colspan="2">Information</td>';
240 print '</tr>';
241 $var = !$var;
242 print '<tr class="oddeven">';
243 print '<td>Caching enabled</td>';
244 print '<td align="right">'.($info['cache']?'yes':'no').'</td>';
245 print '</tr>';
246 $var = !$var;
247 print '<tr class="oddeven">';
248 print '<td>Optimizer enabled</td>';
249 print '<td align="right">'.$info['optimizer']?'yes':'no'.'</td>';
250 print '</tr>';
251 $var = !$var;
252 print '<tr class="oddeven">';
253 print '<td>Memory usage</td>';
254 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>';
255 print '</tr>';
256 $var = ! $var;
257 print '<tr class="oddeven">';
258 print '<td>Free memory in reserved cache</td>';
259 print '<td align="right">'.number_format($info['memoryAvailable']/(1024*1024), 2).'MB</td>';
260 print '</tr>';
261 $var = ! $var;
262 print '<tr class="oddeven">';
263 print '<td>Cached scripts</td>';
264 print '<td align="right">'.$info['cachedScripts'].'</td>';
265 print '</tr>';
266 $var = ! $var;
267 print '<tr class="oddeven">';
268 print '<td>Removed scripts</td>';
269 print '<td align="right">'.$info['removedScripts'].'</td>';
270 print '</tr>';
271 $var = ! $var;
272 print '<tr class="oddeven">';
273 print '<td>Cached keys</td>';
274 print '<td align="right">'.(isset($info['cachedKeys'])?$info['cachedKeys']:'').'</td>';
275 print '</tr>';
276 print '</table>';
277 
278 $var=true;
279 
280 $resCached = @eaccelerator_cached_scripts(); // If success return an array
281 $resRemoved = @eaccelerator_removed_scripts();
282 
283 if (is_array($resCached) || is_array($resRemoved)) {
284  print "<br>";
285  print '<form name="ea_control" method="post">';
286  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
287  print '<table class="noborder">';
288  print '<tr class="liste_titre"><td colspan="2">Actions</td></tr>';
289 
290  if (is_array($resCached)) {
291  $var = ! $var;
292  print '<tr class="oddeven">';
293  print "<td>Caching</td>";
294  print '<td align="right"><input type="submit" class="butAction" name="caching" value="'. ($info['cache']?'disable':'enable') .'" /></td>';
295  print "</tr>";
296  $var = ! $var;
297  print '<tr class="oddeven">';
298  print "<td>Optimizer</td>";
299  print '<td align="right"><input type="submit" class="butAction" name="optimizer" value="'. ($info['optimizer']?'disable':'enable') .'" /></td>';
300  print "</tr>";
301  }
302 
303  if (is_array($resRemoved)) {
304  $var = ! $var;
305  print '<tr class="oddeven">';
306  print "<td>Clear cache</td>";
307  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>';
308  print "</tr>";
309  $var = ! $var;
310  print '<tr class="oddeven">';
311  print "<td>Clean cache</td>";
312  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>';
313  print "</tr>";
314  $var = ! $var;
315  print '<tr class="oddeven">';
316  print "<td>Purge cache</td>";
317  print '<td align="right"><input type="submit" class="butAction" name="purge" value="purge" title="remove all \'removed\' scripts from shared memory" /></td>';
318  print "</tr></table></form>";
319  }
320 
321  if (is_array($resCached)) {
322  print "<br><br>";
323  print "<b>Cached scripts</b><br>";
324  create_script_table($resCached);
325  }
326 
327  if (is_array($resRemoved)) {
328  print "<br><br>";
329  print "<b>Removed scripts</b><br>";
330  create_script_table($resRemoved);
331  }
332 } else {
333  print "<br><br>";
334  print "Check in your <b>php.ini</b> that <b>eaccelerator.allowed_admin_path</b> parameter is : ";
335  print "<br><br>";
336  print "<b>".$_SERVER["SCRIPT_FILENAME"]."</b>";
337  print "<br><br>";
338 }
339 
340 if (function_exists('eaccelerator_get')) {
341  print '<br><br>';
342  print '<b>Cached keys</b><br>';
343  $res=eaccelerator_list_keys();
344  create_key_table($res);
345 }
346 
347 print "<br><br>";
348 
349 
350 llxFooter();
351 
352 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
revcompare($x, $y)
Compare revisions.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
create_script_table($list)
Output table.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
create_key_table($list)
Output table.
if(!is_array($info)) compare($x, $y)
Compare revisions.