2, 'used_memory_percentage_high_threshold' => 80, 'used_memory_percentage_mid_threshold' => 60, 'allow_invalidate' => true ); class OpCacheService { protected $config; protected $status; protected $functions; private function __construct() { $this->data = $this->compileState(); } public static function init() { $self = new self; if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) { echo json_encode($self->getData(@$_GET['section'] ?: null)); exit; } else if ((isset($_GET['reset']))) { $self->resetCache(); } else if ((isset($_GET['invalidate']))) { $self->resetCache($_GET['invalidate']); } return $self; } public function getData($section = null) { if ($section === null) { return $this->data; } $section = strtolower($section); return (isset($this->data[$section]) ? $this->data[$section] : null ); } public function resetCache($file = null) { $success = false; if ($file === null) { $success = opcache_reset(); } else if (function_exists('opcache_invalidate')) { $success = opcache_invalidate(urldecode($file), true); } if ($success) { $this->compileState(); } return $success; } protected function compileState() { $config = opcache_get_configuration(); $memsize = function($size, $precision = 3, $space = false) { $i = 0; $val = array(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); while (($size / 1024) > 1) { $size /= 1024; ++$i; } return sprintf("%.{$precision}f%s%s", $size, (($space && $i) ? ' ' : ''), $val[$i]); }; $status = opcache_get_status(); if (!empty($status['scripts'])) { uasort($status['scripts'], function($a, $b) { return $a['hits'] < $b['hits']; }); $this->data['files'] = $status['scripts']; } $overview = array_merge( $status['memory_usage'], $status['opcache_statistics'], [ 'used_memory_percentage' => round(100 * ( ($status['memory_usage']['used_memory'] + $status['memory_usage']['wasted_memory']) / $config['directives']['opcache.memory_consumption'])), 'hit_rate_percentage' => round($status['opcache_statistics']['opcache_hit_rate']), 'wasted_percentage' => round($status['memory_usage']['current_wasted_percentage'], 2), 'readable' => [ 'total_memory' => $memsize($config['directives']['opcache.memory_consumption']), 'used_memory' => $memsize($status['memory_usage']['used_memory']), 'free_memory' => $memsize($status['memory_usage']['free_memory']), 'wasted_memory' => $memsize($status['memory_usage']['wasted_memory']), 'num_cached_scripts' => number_format($status['opcache_statistics']['num_cached_scripts']), 'hits' => number_format($status['opcache_statistics']['hits']), 'misses' => number_format($status['opcache_statistics']['misses']), 'blacklist_miss' => number_format($status['opcache_statistics']['blacklist_misses']), 'num_cached_keys' => number_format($status['opcache_statistics']['num_cached_keys']), 'max_cached_keys' => number_format($status['opcache_statistics']['max_cached_keys']), 'start_time' => date_format(date_create("@{$status['opcache_statistics']['start_time']}"), 'Y-m-d H:i:s'), 'last_restart_time' => ($status['opcache_statistics']['last_restart_time'] == 0 ? 'never' : date_format(date_create("@{$status['opcache_statistics']['last_restart_time']}"), 'Y-m-d H:i:s') ) ] ] ); ksort($config['directives']); $version = array_merge( $config['version'], [ 'php' => phpversion(), 'server' => $_SERVER['SERVER_SOFTWARE'], 'host' => (function_exists('gethostname') ? gethostname() : (php_uname('n') ?: (empty($_SERVER['SERVER_NAME']) ? $_SERVER['HOST_NAME'] : $_SERVER['SERVER_NAME'] ) ) ) ] ); return [ 'version' => $version, 'overview' => $overview, 'files' => $status['scripts'], 'directives' => $config['directives'], 'blacklist' => $config['blacklist'], 'functions' => get_extension_funcs('Zend OPcache') ]; } } $opcache = OpCacheService::init(); ?>

Overview

getData('overview'); ?>

memory usage

%

hit rate

%

total memory:

used memory:

free memory:

wasted memory: (%)

number of cached files:

number of hits:

number of misses:

blacklist misses:

number of cached keys:

max cached keys:

Enable real-time update of stats

getData('version'); ?>
General info
Zend OPcache
PHP
Host
Server Software
Start time
Last reset
getData('directives'); ?> $v): ?>
Directives
true' : 'false') : (empty($v) ? 'no value' : $v)); ?>
getData('functions'); ?>
Available functions

File usage

file cached

getData('files'); ?>
Script Details

'; echo join(DIRECTORY_SEPARATOR, array_slice($parts, $settings['compress_path_threshold'])); if (count($parts) > $settings['compress_path_threshold']) { echo DIRECTORY_SEPARATOR; } echo "{$base}"; } else { echo htmlentities($f['full_path'], ENT_COMPAT, 'UTF-8'); } ?>

Force file invalidation

hits: , memory:
last used:
has been invalidated