diff --git a/admin_opcacheinfo.php b/admin_opcacheinfo.php new file mode 100644 index 00000000..9d45de9b --- /dev/null +++ b/admin_opcacheinfo.php @@ -0,0 +1,159 @@ + (2016) + * @author Froxlor team (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Panel + * + * Based on https://github.com/amnuts/opcache-gui + * + */ + +define('AREA', 'admin'); +require './lib/init.php'; + + +if ($action == 'reset' && + function_exists('opcache_reset') && + $userinfo['change_serversettings'] == '1' +) { + opcache_reset(); + $log->logAction(ADM_ACTION, LOG_INFO, "reseted OPcache"); + header('Location: ' . $linker->getLink(array('section' => 'opcacheinfo', 'page' => 'showinfo'))); + exit(); +} + +if (!function_exists('opcache_get_configuration') +) { + standard_error($lng['error']['no_opcacheinfo']); + exit(); +} + +if ($page == 'showinfo' +) { + + $opcache_info = opcache_get_configuration(); + $opcache_status = opcache_get_status(false); + $time = time(); + $log->logAction(ADM_ACTION, LOG_NOTICE, "viewed OPcache info"); + + $runtimelines = ''; + if (isset($opcache_info['directives']) && is_array($opcache_info['directives'])) { + foreach ($opcache_info['directives'] as $name => $value) { + $linkname= str_replace('_', '-', $name); + if ($name=='opcache.optimization_level' && is_integer($value)) { + $value='0x'.dechex($value); + } + if ($name=='opcache.memory_consumption' && is_integer($value) && $value%(1024*1024)==0) { + $value=$value/(1024*1024); + } + if ($value===null || $value==='') { + $value=$lng['opcacheinfo']['novalue']; + } + if ($value===true) { + $value=$lng['opcacheinfo']['true']; + } + if ($value===false) { + $value=$lng['opcacheinfo']['false']; + } + if (is_integer($value)) { + $value=number_format($value,0,'.',' '); + } + $name=str_replace('_', ' ', $name); + eval("\$runtimelines.=\"" . getTemplate("settings/opcacheinfo/runtime_line") . "\";"); + } + } + + $cachehits=@$opcache_status['opcache_statistics']['hits'] ?: 0; + $cachemiss=@$opcache_status['opcache_statistics']['misses'] ?: 0; + $blacklistmiss=@$opcache_status['opcache_statistics']['blacklist_misses'] ?: 0; + $cachetotal=$cachehits+$cachemiss+$blacklistmiss; + + $general=array( + 'version' => (isset($opcache_info['version']['opcache_product_name']) ? $opcache_info['version']['opcache_product_name'].' ' : '').$opcache_info['version']['version'], + 'phpversion' => phpversion(), + 'start_time' => @$opcache_status['opcache_statistics']['start_time'] ? date('Y-m-d H:i:s',$opcache_status['opcache_statistics']['start_time']) : '', + 'last_restart_time' => @$opcache_status['opcache_statistics']['last_restart_time'] ? date('Y-m-d H:i:s',$opcache_status['opcache_statistics']['last_restart_time']) : $lng['opcacheinfo']['never'], + 'oom_restarts' => number_format(@$opcache_status['opcache_statistics']['oom_restarts'] ?: 0,0,'.',' '), + 'hash_restarts' => number_format(@$opcache_status['opcache_statistics']['hash_restarts'] ?: 0,0,'.',' '), + 'manual_restarts' => number_format(@$opcache_status['opcache_statistics']['manual_restarts'] ?: 0,0,'.',' '), + 'status' => (@$opcache_status['restart_in_progress'] ? $lng['opcacheinfo']['restartinprogress'] : + (@$opcache_status['restart_pending'] ? $lng['opcacheinfo']['restartpending'] : + (@$opcache_status['cache_full'] ? $lng['opcacheinfo']['cachefull'] : + (@$opcache_status['opcache_enabled'] ? $lng['opcacheinfo']['enabled'] : $lng['opcacheinfo']['novalue'])))), + 'cachedscripts' => number_format(@$opcache_status['opcache_statistics']['num_cached_scripts'] ?: 0,0,'.',' '), + 'cachehits' => number_format($cachehits,0,'.',' ') . ($cachetotal>0 ? sprintf(" (%.1f %%)", $cachehits/($cachetotal)*100) : ''), + 'cachemiss' => number_format($cachemiss,0,'.',' ') . ($cachetotal>0 ? sprintf(" (%.1f %%)", $cachemiss/($cachetotal)*100) : ''), + 'blacklistmiss' => number_format($blacklistmiss,0,'.',' ') . ($cachetotal>0 ? sprintf(" (%.1f %%)", $blacklistmiss/($cachetotal)*100) : ''), + ); + + $usedmem=@$opcache_status['memory_usage']['used_memory'] ?: 0; + $usedmemstr=bsize($usedmem); + $freemem=@$opcache_status['memory_usage']['free_memory'] ?: 0; + $freememstr=bsize($freemem); + $totalmem=$usedmem+$freemem; + $wastedmem=@$opcache_status['memory_usage']['wasted_memory'] ?: 0; + $wastedmemstr=bsize($wastedmem); + if ($totalmem) { + $memory=array( + 'total' => bsize($totalmem), + 'used' => $usedmemstr . ($totalmem>0 ? sprintf(" (%.1f %%)", $usedmem/($totalmem)*100) : ''), + 'free' => $freememstr . ($totalmem>0 ? sprintf(" (%.1f %%)", $freemem/($totalmem)*100) : ''), + 'wasted' => $wastedmemstr . ($totalmem>0 ? sprintf(" (%.1f %%)", $wastedmem/($totalmem)*100) : ''), + ); + } + + if (isset($opcache_status['interned_strings_usage'])) { + $usedstring=@$opcache_status['interned_strings_usage']['used_memory'] ?: 0; + $usedstringstr=bsize($usedstring); + $freestring=@$opcache_status['interned_strings_usage']['free_memory'] ?: 0; + $freestringstr=bsize($freestring); + $totalstring=$usedstring+$freestring; + $stringbuffer=array( + 'total' => bsize($totalstring), + 'used' => $usedstringstr . ($totalstring>0 ? sprintf(" (%.1f %%)", $usedstring/$totalstring*100) : ''), + 'free' => $freestringstr . ($totalstring>0 ? sprintf(" (%.1f %%)", $freestring/$totalstring*100) : ''), + 'strcount' => number_format(@$opcache_status['interned_strings_usage']['number_of_strings'] ?: 0,0,'.',' '), + ); + } + + $usedkey=@$opcache_status['opcache_statistics']['num_cached_keys'] ?: 0; + $usedkeystr=number_format($usedkey,0,'.',' '); + $totalkey=@$opcache_status['opcache_statistics']['max_cached_keys'] ?: 0; + $wastedkey=$usedkey - (@$opcache_status['opcache_statistics']['num_cached_scripts'] ?: 0); + if (isset($opcache_status['opcache_statistics'])) { + $keystat=array( + 'total' => number_format($totalkey,0,'.',' '), + 'used' => $usedkeystr . ($totalkey>0 ? sprintf(" (%.1f %%)", $usedkey/($totalkey)*100) : ''), + 'wasted' => number_format($wastedkey,0,'.',' ') . ($totalkey>0 ? sprintf(" (%.1f %%)", $wastedkey/($totalkey)*100) : ''), + ); + } + + $blacklistlines = ''; + if (isset($opcache_info['blacklist']) && is_array($opcache_info['blacklist'])) { + foreach ($opcache_info['blacklist'] as $value) { + eval("\$blacklistlines.=\"" . getTemplate("settings/opcacheinfo/blacklist_line") . "\";"); + } + } + + eval("echo \"" . getTemplate("settings/opcacheinfo/showinfo") . "\";"); + +} + +function bsize($s) { + foreach (array('', 'K', 'M', 'G') as $i => $k) { + if ($s < 1024) + break; + $s/=1024; + } + return sprintf("%5.1f %sBytes", $s, $k); +} diff --git a/lib/navigation/00.froxlor.main.php b/lib/navigation/00.froxlor.main.php index 809403f8..826552a9 100644 --- a/lib/navigation/00.froxlor.main.php +++ b/lib/navigation/00.froxlor.main.php @@ -223,6 +223,14 @@ return array ( function_exists('apcu_cache_info') === true ), ), + array ( + 'url' => 'admin_opcacheinfo.php?page=showinfo', + 'label' => $lng['admin']['opcacheinfo'], + 'required_resources' => 'change_serversettings', + 'show_element' => ( + function_exists('opcache_get_configuration') === true + ), + ), array ( 'url' => 'admin_ipsandports.php?page=ipsandports', 'label' => $lng['admin']['ipsandports']['ipsandports'], diff --git a/lng/english.lng.php b/lng/english.lng.php index 1f5c0cff..d369cb3b 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1883,3 +1883,44 @@ $lng['apcuinfo']['used'] = 'Used'; $lng['apcuinfo']['hitmiss'] = 'Hits & Misses'; $lng['apcuinfo']['detailmem'] = 'Detailed Memory Usage and Fragmentation'; $lng['apcuinfo']['fragment'] = 'Fragmentation'; + +// Added for opcache info +$lng['admin']['opcacheinfo'] = 'OPcache info'; +$lng['error']['no_opcacheinfo'] = 'No cache info available. OPCache does not appear to be running.'; +$lng['opcacheinfo']['generaltitle'] = 'General Information'; +$lng['opcacheinfo']['resetcache'] = 'Reset OPcache'; +$lng['opcacheinfo']['version'] = 'OPCache version'; +$lng['opcacheinfo']['phpversion'] = 'PHP version'; +$lng['opcacheinfo']['runtimeconf'] = 'Runtime Configuration'; +$lng['opcacheinfo']['start'] = 'Start time'; +$lng['opcacheinfo']['lastreset'] = 'Last restart'; +$lng['opcacheinfo']['oomrestarts'] = 'OOM restart count'; +$lng['opcacheinfo']['hashrestarts'] = 'Hash restart count'; +$lng['opcacheinfo']['manualrestarts'] = 'Manual restart count'; +$lng['opcacheinfo']['hitsc'] = 'Hits count'; +$lng['opcacheinfo']['missc'] = 'Miss count'; +$lng['opcacheinfo']['blmissc'] = 'Blacklist miss count'; +$lng['opcacheinfo']['status'] = 'Status'; +$lng['opcacheinfo']['never'] = 'never'; +$lng['opcacheinfo']['enabled'] = 'OPcache Enabled'; +$lng['opcacheinfo']['cachefull'] = 'Cache full'; +$lng['opcacheinfo']['restartpending'] = 'Pending restart'; +$lng['opcacheinfo']['restartinprogress'] = 'Restart in progress'; +$lng['opcacheinfo']['cachedscripts'] = 'Cached scripts count'; +$lng['opcacheinfo']['memusage'] = 'Memory usage'; +$lng['opcacheinfo']['totalmem'] = 'Total memory'; +$lng['opcacheinfo']['usedmem'] = 'Used memory'; +$lng['opcacheinfo']['freemem'] = 'Free memory'; +$lng['opcacheinfo']['wastedmem'] = 'Wasted memory'; +$lng['opcacheinfo']['maxkey'] = 'Maximum keys'; +$lng['opcacheinfo']['usedkey'] = 'Used keys'; +$lng['opcacheinfo']['wastedkey'] = 'Wasted keys'; +$lng['opcacheinfo']['strinterning'] = 'String interning'; +$lng['opcacheinfo']['strcount'] = 'String count'; +$lng['opcacheinfo']['keystat'] = 'Cached keys statistic'; +$lng['opcacheinfo']['used'] = 'Used'; +$lng['opcacheinfo']['free'] = 'Free'; +$lng['opcacheinfo']['blacklist'] = 'Blacklist'; +$lng['opcacheinfo']['novalue'] = 'no value'; +$lng['opcacheinfo']['true'] = 'true'; +$lng['opcacheinfo']['false'] = 'false'; diff --git a/templates/Sparkle/admin/settings/opcacheinfo/blacklist_line.tpl b/templates/Sparkle/admin/settings/opcacheinfo/blacklist_line.tpl new file mode 100644 index 00000000..7bf15491 --- /dev/null +++ b/templates/Sparkle/admin/settings/opcacheinfo/blacklist_line.tpl @@ -0,0 +1,3 @@ + + {$value} + diff --git a/templates/Sparkle/admin/settings/opcacheinfo/runtime_line.tpl b/templates/Sparkle/admin/settings/opcacheinfo/runtime_line.tpl new file mode 100644 index 00000000..ca26ea49 --- /dev/null +++ b/templates/Sparkle/admin/settings/opcacheinfo/runtime_line.tpl @@ -0,0 +1,4 @@ + + {$name} + {$value} + diff --git a/templates/Sparkle/admin/settings/opcacheinfo/showinfo.tpl b/templates/Sparkle/admin/settings/opcacheinfo/showinfo.tpl new file mode 100644 index 00000000..0a688fe5 --- /dev/null +++ b/templates/Sparkle/admin/settings/opcacheinfo/showinfo.tpl @@ -0,0 +1,201 @@ +$header +
+
+

+   + {$lng['admin']['opcacheinfo']} +

+
+ +
+
+ + +
+ +
+ {$lng['opcacheinfo']['memusage']}
+ + {$lng['opcacheinfo']['used']}: {$usedmemstr}
+ {$lng['opcacheinfo']['free']}: {$freememstr} +
+
+
+ +
+ {$lng['opcacheinfo']['wastedmem']}
+ + {$wastedmemstr} + +
+
+ +
+ +
+ {$lng['opcacheinfo']['strinterning']}
+ + {$lng['opcacheinfo']['used']}: {$usedstringstr}
+ {$lng['opcacheinfo']['free']}: {$freestringstr} +
+
+
+ +
+ +
+ {$lng['opcacheinfo']['usedkey']}
+ + {$usedkeystr} + +
+
+ +
+ +
+ {$lng['opcacheinfo']['hitsc']} +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {$runtimelines} + + + + + + + {$blacklistlines} + + +
{$lng['opcacheinfo']['generaltitle']} + {$lng['opcacheinfo']['resetcache']} +   +
{$lng['opcacheinfo']['version']}{$general['version']}
{$lng['opcacheinfo']['phpversion']}{$general['phpversion']}
{$lng['opcacheinfo']['start']}{$general['start_time']}
{$lng['opcacheinfo']['lastreset']}{$general['last_restart_time']}
{$lng['opcacheinfo']['oomrestarts']}{$general['oom_restarts']}
{$lng['opcacheinfo']['hashrestarts']}{$general['hash_restarts']}
{$lng['opcacheinfo']['manualrestarts']}{$general['manual_restarts']}
{$lng['opcacheinfo']['status']}{$general['status']}
{$lng['opcacheinfo']['cachedscripts']}{$general['cachedscripts']}
{$lng['opcacheinfo']['hitsc']}{$general['cachehits']}
{$lng['opcacheinfo']['missc']}{$general['cachemiss']}
{$lng['opcacheinfo']['blmissc']}{$general['blacklistmiss']}
{$lng['opcacheinfo']['memusage']}
{$lng['opcacheinfo']['totalmem']}{$memory['total']}
{$lng['opcacheinfo']['usedmem']}{$memory['used']}
{$lng['opcacheinfo']['freemem']}{$memory['free']}
{$lng['opcacheinfo']['wastedmem']}{$memory['wasted']}
{$lng['opcacheinfo']['strinterning']}
{$lng['opcacheinfo']['totalmem']}{$stringbuffer['total']}
{$lng['opcacheinfo']['usedmem']}{$stringbuffer['used']}
{$lng['opcacheinfo']['freemem']}{$stringbuffer['free']}
{$lng['opcacheinfo']['strcount']}{$stringbuffer['strcount']}
{$lng['opcacheinfo']['keystat']}
{$lng['opcacheinfo']['maxkey']}{$keystat['total']}
{$lng['opcacheinfo']['usedkey']}{$keystat['used']}
{$lng['opcacheinfo']['wastedkey']}{$keystat['wasted']}
{$lng['opcacheinfo']['runtimeconf']}
{$lng['opcacheinfo']['blacklist']}
+ +
+ +
+$footer