2016-01-17 00:17:43 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
use Froxlor\UI\Panel\UI;
|
|
|
|
|
2016-01-17 00:17:43 +00:00
|
|
|
/*
|
2018-12-21 11:24:07 +00:00
|
|
|
* +----------------------------------------------------------------------+
|
|
|
|
* | APC |
|
|
|
|
* +----------------------------------------------------------------------+
|
|
|
|
* | Copyright (c) 2006-2011 The PHP Group |
|
|
|
|
* +----------------------------------------------------------------------+
|
|
|
|
* | This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
* | that is bundled with this package in the file LICENSE, and is |
|
|
|
|
* | available through the world-wide-web at the following url: |
|
|
|
|
* | http://www.php.net/license/3_01.txt |
|
|
|
|
* | If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
* | obtain it through the world-wide-web, please send a note to |
|
|
|
|
* | license@php.net so we can mail you a copy immediately. |
|
|
|
|
* +----------------------------------------------------------------------+
|
|
|
|
* | Authors: Ralf Becker <beckerr@php.net> |
|
|
|
|
* | Rasmus Lerdorf <rasmus@php.net> |
|
|
|
|
* | Ilia Alshanetsky <ilia@prohost.org> |
|
|
|
|
* +----------------------------------------------------------------------+
|
|
|
|
*
|
|
|
|
* All other licensing and usage conditions are those of the PHP Group.
|
|
|
|
*
|
|
|
|
* Based on https://github.com/krakjoe/apcu/blob/master/apc.php
|
|
|
|
* Implemented into Froxlor: Janos Muzsi <muzsij@hypernics.hu>
|
|
|
|
*
|
2016-01-17 00:17:43 +00:00
|
|
|
*/
|
2022-02-20 17:00:44 +00:00
|
|
|
|
|
|
|
const AREA = 'admin';
|
|
|
|
require __DIR__ . '/lib/init.php';
|
2016-01-17 00:17:43 +00:00
|
|
|
|
|
|
|
$horizontal_bar_size = 950; // 1280px window width
|
|
|
|
|
2018-12-22 07:15:31 +00:00
|
|
|
if ($action == 'delete' && function_exists('apcu_clear_cache') && $userinfo['change_serversettings'] == '1') {
|
2018-12-21 11:24:07 +00:00
|
|
|
apcu_clear_cache();
|
2018-12-26 14:51:26 +00:00
|
|
|
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_INFO, "cleared APCu cache");
|
2018-12-21 11:24:07 +00:00
|
|
|
header('Location: ' . $linker->getLink(array(
|
|
|
|
'section' => 'apcuinfo',
|
|
|
|
'page' => 'showinfo'
|
|
|
|
)));
|
|
|
|
exit();
|
2016-01-17 00:17:43 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
if (!function_exists('apcu_cache_info') || !function_exists('apcu_sma_info')) {
|
2018-12-22 07:15:31 +00:00
|
|
|
\Froxlor\UI\Response::standard_error($lng['error']['no_apcuinfo']);
|
2016-01-17 00:17:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
if ($page == 'showinfo') {
|
|
|
|
$cache = apcu_cache_info();
|
|
|
|
$mem = apcu_sma_info();
|
|
|
|
$time = time();
|
2018-12-26 14:51:26 +00:00
|
|
|
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_apcuinfo");
|
2018-12-21 11:24:07 +00:00
|
|
|
|
|
|
|
// check for possible empty values that are used in the templates
|
2022-03-26 15:47:46 +00:00
|
|
|
if (!isset($cache['file_upload_progress'])) {
|
2018-12-22 07:15:31 +00:00
|
|
|
$cache['file_upload_progress'] = $lng['logger']['unknown'];
|
2018-12-21 11:24:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
if (!isset($cache['num_expunges'])) {
|
2018-12-22 07:15:31 +00:00
|
|
|
$cache['num_expunges'] = $lng['logger']['unknown'];
|
2018-12-21 11:24:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
$overview = [
|
|
|
|
'mem_size' => $mem['num_seg'] * $mem['seg_size'],
|
|
|
|
'mem_avail' => $mem['avail_mem'],
|
|
|
|
'mem_used' => ($mem['num_seg'] * $mem['seg_size']) - $mem['avail_mem'],
|
|
|
|
'seg_size' => bsize($mem['seg_size']),
|
|
|
|
'num_hits' => $cache['num_hits'],
|
|
|
|
'num_misses' => $cache['num_misses'],
|
|
|
|
'num_inserts' => $cache['num_inserts'],
|
|
|
|
'req_rate_user' => sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits'] + $cache['num_misses']) / ($time - $cache['start_time'])) : 0),
|
|
|
|
'hit_rate_user' => sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits']) / ($time - $cache['start_time'])) : 0),
|
|
|
|
'miss_rate_user' => sprintf("%.2f", $cache['num_misses'] ? (($cache['num_misses']) / ($time - $cache['start_time'])) : 0),
|
|
|
|
'insert_rate_user' => sprintf("%.2f", $cache['num_inserts'] ? (($cache['num_inserts']) / ($time - $cache['start_time'])) : 0),
|
|
|
|
'apcversion' => phpversion('apcu'),
|
|
|
|
'phpversion' => phpversion(),
|
|
|
|
'number_vars' => $cache['num_entries'],
|
|
|
|
'size_vars' => bsize($cache['mem_size']),
|
|
|
|
'num_hits_and_misses' => 0 >= ($cache['num_hits'] + $cache['num_misses']) ? 1 : ($cache['num_hits'] + $cache['num_misses']),
|
|
|
|
'file_upload_progress' => $cache['file_upload_progress'],
|
|
|
|
'num_expunges' => $cache['num_expunges'],
|
|
|
|
'host' => (function_exists('gethostname')
|
|
|
|
? gethostname()
|
|
|
|
: (php_uname('n')
|
|
|
|
?: (empty($_SERVER['SERVER_NAME'])
|
|
|
|
? $_SERVER['HOST_NAME']
|
|
|
|
: $_SERVER['SERVER_NAME']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'server' => $_SERVER['SERVER_SOFTWARE'] ?: '',
|
|
|
|
'start_time' => $cache['start_time'],
|
|
|
|
'uptime' => duration($cache['start_time'])
|
|
|
|
];
|
|
|
|
|
|
|
|
$overview['mem_used_percentage'] = number_format(($overview['mem_used'] / $overview['mem_avail']) * 100, 1);
|
|
|
|
$overview['num_hits_percentage'] = number_format(($overview['num_hits'] / $overview['num_hits_and_misses']) * 100, 1);
|
|
|
|
$overview['num_misses_percentage'] = number_format(($overview['num_misses'] / $overview['num_hits_and_misses']) * 100, 1);
|
|
|
|
$overview['readable'] = [
|
|
|
|
'mem_size' => bsize($overview['mem_size']),
|
|
|
|
'mem_avail' => bsize($overview['mem_avail']),
|
|
|
|
'mem_used' => bsize($overview['mem_used']),
|
|
|
|
'num_hits' => number_format($overview['num_hits']),
|
|
|
|
'num_misses' => number_format($overview['num_misses']),
|
|
|
|
'number_vars' => number_format($overview['number_vars']),
|
|
|
|
];
|
|
|
|
|
|
|
|
$overview['runtimelines'] = [];
|
2018-12-21 11:24:07 +00:00
|
|
|
foreach (ini_get_all('apcu') as $name => $v) {
|
|
|
|
$value = $v['local_value'];
|
2022-03-26 15:47:46 +00:00
|
|
|
$overview['runtimelines'][$name] = $value;
|
2018-12-21 11:24:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
// Fragementation: (freeseg - 1) / total_seg
|
2018-12-21 11:24:07 +00:00
|
|
|
$nseg = $freeseg = $fragsize = $freetotal = 0;
|
2022-03-26 15:47:46 +00:00
|
|
|
for ($i = 0; $i < $mem['num_seg']; $i++) {
|
2018-12-21 11:24:07 +00:00
|
|
|
$ptr = 0;
|
|
|
|
foreach ($mem['block_lists'][$i] as $block) {
|
|
|
|
if ($block['offset'] != $ptr) {
|
2022-03-26 15:47:46 +00:00
|
|
|
++$nseg;
|
2018-12-21 11:24:07 +00:00
|
|
|
}
|
|
|
|
$ptr = $block['offset'] + $block['size'];
|
|
|
|
/* Only consider blocks <5M for the fragmentation % */
|
2022-03-26 15:47:46 +00:00
|
|
|
if ($block['size'] < (5 * 1024 * 1024)) $fragsize += $block['size'];
|
2018-12-21 11:24:07 +00:00
|
|
|
$freetotal += $block['size'];
|
|
|
|
}
|
|
|
|
$freeseg += count($mem['block_lists'][$i]);
|
|
|
|
}
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
$overview['fragmentation'] = [];
|
2018-12-21 11:24:07 +00:00
|
|
|
if ($freeseg > 1) {
|
2022-03-26 15:47:46 +00:00
|
|
|
$overview['fragmentation']['used_percentage'] = number_format(($fragsize / $freetotal) * 100, 1);
|
|
|
|
$overview['fragmentation']['used_bytes'] = $fragsize;
|
|
|
|
$overview['fragmentation']['total_bytes'] = $freetotal;
|
|
|
|
$overview['fragmentation']['num_frags'] = $freeseg;
|
|
|
|
$overview['fragmentation']['readable'] = [
|
|
|
|
'used_bytes' => bsize($fragsize),
|
|
|
|
'total_bytes' => bsize($freetotal),
|
|
|
|
'num_frags' => number_format($freeseg)
|
|
|
|
];
|
2018-12-21 11:24:07 +00:00
|
|
|
} else {
|
2022-03-26 15:47:46 +00:00
|
|
|
$overview['fragmentation'] = 0;
|
2018-12-21 11:24:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 15:47:46 +00:00
|
|
|
UI::view('settings/apcuinfo.html.twig', [
|
|
|
|
'apcuinfo' => $overview
|
|
|
|
]);
|
2016-01-17 00:17:43 +00:00
|
|
|
}
|
|
|
|
// pretty printer for byte values
|
2022-03-26 15:47:46 +00:00
|
|
|
function bsize($size)
|
2018-12-21 11:24:07 +00:00
|
|
|
{
|
2022-03-26 15:47:46 +00:00
|
|
|
$i = 0;
|
|
|
|
$val = ['b', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
|
|
while (($size / 1024) > 1) {
|
|
|
|
$size /= 1024;
|
|
|
|
++$i;
|
|
|
|
}
|
|
|
|
return sprintf(
|
|
|
|
'%.2f%s%s',
|
|
|
|
$size,
|
2018-12-21 11:24:07 +00:00
|
|
|
'',
|
2022-03-26 15:47:46 +00:00
|
|
|
$val[$i]
|
|
|
|
);
|
2016-01-17 00:17:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
function duration($ts)
|
|
|
|
{
|
|
|
|
global $time;
|
2022-03-26 15:47:46 +00:00
|
|
|
$years = (int)((($time - $ts) / (7 * 86400)) / 52.177457);
|
|
|
|
$rem = (int)(($time - $ts) - ($years * 52.177457 * 7 * 86400));
|
|
|
|
$weeks = (int)(($rem) / (7 * 86400));
|
|
|
|
$days = (int)(($rem) / 86400) - $weeks * 7;
|
|
|
|
$hours = (int)(($rem) / 3600) - $days * 24 - $weeks * 7 * 24;
|
|
|
|
$mins = (int)(($rem) / 60) - $hours * 60 - $days * 24 * 60 - $weeks * 7 * 24 * 60;
|
2018-12-21 11:24:07 +00:00
|
|
|
$str = '';
|
2022-03-26 15:47:46 +00:00
|
|
|
if ($years == 1) $str .= "$years year, ";
|
|
|
|
if ($years > 1) $str .= "$years years, ";
|
|
|
|
if ($weeks == 1) $str .= "$weeks week, ";
|
|
|
|
if ($weeks > 1) $str .= "$weeks weeks, ";
|
|
|
|
if ($days == 1) $str .= "$days day,";
|
|
|
|
if ($days > 1) $str .= "$days days,";
|
|
|
|
if ($hours == 1) $str .= " $hours hour and";
|
|
|
|
if ($hours > 1) $str .= " $hours hours and";
|
|
|
|
if ($mins == 1) $str .= " 1 minute";
|
|
|
|
else $str .= " $mins minutes";
|
2018-12-21 11:24:07 +00:00
|
|
|
return $str;
|
2016-01-17 00:17:43 +00:00
|
|
|
}
|