dolibarr  9.0.0
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,$langs;
120 
121  if (GETPOT('order') == "asc" || GETPOST('order') =="desc") {
122  $order = GETPOST('order');
123  } else {
124  $order = "asc";
125  }
126 
127  if (GETPOST('order')) {
128  switch (GETPOST('order')) {
129  case "mtime":
130  case "size":
131  case "reloads":
132  case "hits":
133  $sortby = GETPOST('sort');
134  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
135  break;
136  default:
137  $sortby = "file";
138  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
139  }
140  }
141 
142  print '<table class="noborder">';
143  print '<tr>';
144  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=file&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Filename").'</a>&nbsp;';
145  if($sortby == "file")
146  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
147  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=mtime&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Date").'</a>&nbsp;';
148  if($sortby == "mtime")
149  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
150  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=size&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Size").'</a>&nbsp;';
151  if($sortby == "size")
152  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
153  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=reloads&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Reloads").'</a>&nbsp;';
154  if($sortby == "reloads")
155  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
156  print '<th><a href="'.$_SERVER['PHP_SELF'].'?sort=hits&order='.($order == "asc" ? "desc" : "asc").'">'.$langs->trans("Hits").'</a>&nbsp;';
157  if($sortby == "hits")
158  print ($order == "asc" ? "&darr;" : "&uarr;").'</th>';
159  print '</tr>';
160  switch ($sortby) {
161  case "mtime":
162  case "size":
163  case "reloads":
164  case "hits":
165  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
166  break;
167  case "file":
168  default:
169  $sortby = "file";
170  ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare'));
171  }
172 
173  foreach($list as $script) {
174  print '<tr class="oddeven">';
175  print '<td>'.dol_trunc($script['file'],80,'left').'</td>';
176  print '<td align="center" class="nowrap">'.dol_print_date($script['mtime'],'dayhour').'</td>';
177  print '<td align="right" class="nowrap">'.number_format($script['size'] / 1024, 2).'KB</td>';
178  print '<td align="right" class="nowrap">'.$script['reloads'].' ('.$script['usecount'].')</td>';
179  print '<td align="right" class="nowrap">'.$script['hits'].'</td>';
180  print '</tr>';
181  }
182  print '</table>';
183 }
184 
191 function create_key_table($list)
192 {
193  global $langs;
194 
195  print '<table class="noborder">';
196  print '<tr class="liste_titre">';
197  print '<th>Name</th>';
198  print '<th>Created</th>';
199  print '<th>'.$langs->trans("Size").'</th>';
200  print '<th>ttl</th>';
201  print '</tr>';
202 
203  foreach($list as $key) {
204  print '<tr class="oddeven">';
205  print '<td>'.dol_trunc($key['name'],80,'left').'</td>';
206  print '<td align="center" class="nowrap">'.dol_print_date($key['created'],'dayhour').'</td>';
207  print '<td align="right" class="nowrap">'.number_format($key['size']/1024, 3).'KB</td>';
208  print '<td align="right" class="nowrap">';
209  if ($key['ttl'] == -1) {
210  print 'expired';
211  } elseif ($key['ttl'] == 0) {
212  print 'none';
213  } else {
214  print dol_print_date($key['ttl'],'dayhour');
215  }
216  print '</td>';
217  print '</tr>';
218  }
219  print '</table>';
220 }
221 
222 
223 $form=new Form($db);
224 print load_fiche_titre('Dolibarr eAccelerator '.$info['version'].' control panel','','title_setup');
225 
226 print '<br>';
227 
228 print '<table class="noborder">';
229 print '<tr class="liste_titre">';
230 print '<td colspan="2">Information</td>';
231 print '</tr>';
232 
233 print '<tr class="oddeven">';
234 print '<td>Caching enabled</td>';
235 print '<td align="right">'.($info['cache']?'yes':'no').'</td>';
236 print '</tr>';
237 
238 print '<tr class="oddeven">';
239 print '<td>Optimizer enabled</td>';
240 print '<td align="right">'.$info['optimizer']?'yes':'no'.'</td>';
241 print '</tr>';
242 
243 print '<tr class="oddeven">';
244 print '<td>Memory usage</td>';
245 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>';
246 print '</tr>';
247 
248 print '<tr class="oddeven">';
249 print '<td>Free memory in reserved cache</td>';
250 print '<td align="right">'.number_format($info['memoryAvailable']/(1024*1024), 2).'MB</td>';
251 print '</tr>';
252 
253 print '<tr class="oddeven">';
254 print '<td>Cached scripts</td>';
255 print '<td align="right">'.$info['cachedScripts'].'</td>';
256 print '</tr>';
257 
258 print '<tr class="oddeven">';
259 print '<td>Removed scripts</td>';
260 print '<td align="right">'.$info['removedScripts'].'</td>';
261 print '</tr>';
262 
263 print '<tr class="oddeven">';
264 print '<td>Cached keys</td>';
265 print '<td align="right">'.(isset($info['cachedKeys'])?$info['cachedKeys']:'').'</td>';
266 print '</tr>';
267 print '</table>';
268 
269 $resCached = @eaccelerator_cached_scripts(); // If success return an array
270 $resRemoved = @eaccelerator_removed_scripts();
271 
272 if (is_array($resCached) || is_array($resRemoved)) {
273  print "<br>";
274  print '<form name="ea_control" method="post">';
275  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
276  print '<table class="noborder">';
277  print '<tr class="liste_titre"><td colspan="2">Actions</td></tr>';
278 
279  if (is_array($resCached)) {
280  print '<tr class="oddeven">';
281  print "<td>Caching</td>";
282  print '<td align="right"><input type="submit" class="butAction" name="caching" value="'. ($info['cache']?'disable':'enable') .'" /></td>';
283  print "</tr>";
284 
285  print '<tr class="oddeven">';
286  print "<td>Optimizer</td>";
287  print '<td align="right"><input type="submit" class="butAction" name="optimizer" value="'. ($info['optimizer']?'disable':'enable') .'" /></td>';
288  print "</tr>";
289  }
290 
291  if (is_array($resRemoved)) {
292  print '<tr class="oddeven">';
293  print "<td>Clear cache</td>";
294  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>';
295  print "</tr>";
296 
297  print '<tr class="oddeven">';
298  print "<td>Clean cache</td>";
299  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>';
300  print "</tr>";
301 
302  print '<tr class="oddeven">';
303  print "<td>Purge cache</td>";
304  print '<td align="right"><input type="submit" class="butAction" name="purge" value="purge" title="remove all \'removed\' scripts from shared memory" /></td>';
305  print "</tr></table></form>";
306  }
307 
308  if (is_array($resCached)) {
309  print "<br><br>";
310  print "<b>Cached scripts</b><br>";
311  create_script_table($resCached);
312  }
313 
314  if (is_array($resRemoved)) {
315  print "<br><br>";
316  print "<b>Removed scripts</b><br>";
317  create_script_table($resRemoved);
318  }
319 } else {
320  print "<br><br>";
321  print "Check in your <b>php.ini</b> that <b>eaccelerator.allowed_admin_path</b> parameter is : ";
322  print "<br><br>";
323  print "<b>".$_SERVER["SCRIPT_FILENAME"]."</b>";
324  print "<br><br>";
325 }
326 
327 if (function_exists('eaccelerator_get')) {
328  print '<br><br>';
329  print '<b>Cached keys</b><br>';
330  $res=eaccelerator_list_keys();
331  create_key_table($res);
332 }
333 
334 print "<br><br>";
335 
336 // End of page
337 llxFooter();
338 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
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...
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.
llxHeader()
Empty header.
Definition: wrapper.php:44
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).
if(!is_array($info)) compare($x, $y)
Compare revisions.
create_key_table($list)
Output table.