public function shutdown($context, &$storage) { if ($this->shutdownCalled) { return; } $this->shutdownCalled = true; $status = opcache_get_status(); $config = opcache_get_configuration(); $storage['opMemoryUsage'][] = $status['memory_usage']; $storage['opInternedStringsUsage'][] = $status['interned_strings_usage']; $storage['opStatistics'][] = $status['opcache_statistics']; $storage['opDirectives'][] = $config['directives']; $storage['opVersion'][] = $config['version']; $storage['opBlacklist'][] = $config['blacklist']; $scripts = $status['scripts']; array_walk($scripts, function (&$item, $key) { $item = array_merge(array('name' => basename($item['full_path'])), array('Full Path' => $item['full_path']), $item); $item['memory Consumption'] = round($item['memory_consumption'] / 1024) . " KB ({$item['memory_consumption']} B)"; $item['Last Used'] = $item['last_used']; $item['Last Used Timestamp'] = $item['last_used_timestamp']; $item['created'] = date("D M j G:i:s Y", $item['timestamp']); $item['created Timestamp'] = $item['timestamp']; unset($item['full_path']); unset($item['memory_consumption']); unset($item['last_used']); unset($item['last_used_timestamp']); unset($item['timestamp']); }); $storage['opcacheScripts'] = $scripts; }
public function renderLoadedFiles($tableName) { $status = opcache_get_status(true); $loadedFiles = get_included_files(); $scriptInfo = array(); if (isset($status['scripts']) == false) { return "Failed to load scripts info to generate OPCache info."; } foreach ($loadedFiles as $loadedFile) { $newScriptInfo = array(); if (array_key_exists($loadedFile, $status['scripts']) == true) { $newScriptInfo["memory_consumption"] = $status['scripts'][$loadedFile]["memory_consumption"]; $newScriptInfo["hits"] = $status['scripts'][$loadedFile]["hits"]; } else { $newScriptInfo["memory_consumption"] = "-"; $newScriptInfo["hits"] = "-"; } $newScriptInfo['path'] = $loadedFile; if (mb_strpos($loadedFile, $this->root) === 0) { $newScriptInfo['path'] = '.' . mb_substr($loadedFile, mb_strlen($this->root)); } $scriptInfo[] = $newScriptInfo; } return $this->renderTable($tableName, $scriptInfo); }
private function initOpcacheSpec() { $this->setName(pht('Zend OPcache'))->setVersion(phpversion('Zend OPcache')); if (ini_get('opcache.enable')) { $this->setIsEnabled(true)->setClearCacheCallback('opcache_reset'); $status = opcache_get_status(); $memory = $status['memory_usage']; $mem_used = $memory['used_memory']; $mem_free = $memory['free_memory']; $mem_junk = $memory['wasted_memory']; $this->setUsedMemory($mem_used + $mem_junk); $this->setTotalMemory($mem_used + $mem_junk + $mem_free); $this->setEntryCount($status['opcache_statistics']['num_cached_keys']); $is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode'); $validate = ini_get('opcache.validate_timestamps'); $freq = ini_get('opcache.revalidate_freq'); if ($is_dev && (!$validate || $freq)) { $summary = pht('OPcache is not configured properly for development.'); $message = pht('In development, OPcache should be configured to always reload ' . 'code so nothing needs to be restarted after making changes. To do ' . 'this, enable "%s" and set "%s" to 0.', 'opcache.validate_timestamps', 'opcache.revalidate_freq'); $this->newIssue('extension.opcache.devmode')->setShortName(pht('OPcache Config'))->setName(pht('OPCache Not Configured for Development'))->setSummary($summary)->setMessage($message)->addPHPConfig('opcache.validate_timestamps')->addPHPConfig('opcache.revalidate_freq')->addPhabricatorConfig('phabricator.developer-mode'); } else { if (!$is_dev && $validate) { $summary = pht('OPcache is not configured ideally for production.'); $message = pht('In production, OPcache should be configured to never ' . 'revalidate code. This will slightly improve performance. ' . 'To do this, disable "%s" in your PHP configuration.', 'opcache.validate_timestamps'); $this->newIssue('extension.opcache.production')->setShortName(pht('OPcache Config'))->setName(pht('OPcache Not Configured for Production'))->setSummary($summary)->setMessage($message)->addPHPConfig('opcache.validate_timestamps')->addPhabricatorConfig('phabricator.developer-mode'); } } } else { $this->setIsEnabled(false); $summary = pht('Enabling OPcache will dramatically improve performance.'); $message = pht('The PHP "Zend OPcache" extension is installed, but not enabled in ' . 'your PHP configuration. Enabling it will dramatically improve ' . 'Phabricator performance. Edit the "%s" setting to ' . 'enable the extension.', 'opcache.enable'); $this->newIssue('extension.opcache.enable')->setShortName(pht('OPcache Disabled'))->setName(pht('Zend OPcache Not Enabled'))->setSummary($summary)->setMessage($message)->addPHPConfig('opcache.enable'); } }
/** * {@inheritDoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { // This is needed to support the PHP 5.5 opcache as well as the old ZendOptimizer+-extension. if (function_exists('opcache_get_status')) { $status = opcache_get_status(); $config = opcache_get_configuration(); $version = $config['version']['opcache_product_name'] . ' ' . $config['version']['version']; $stats = $status['opcache_statistics']; $hitrate = $stats['opcache_hit_rate']; } elseif (function_exists('accelerator_get_status')) { $status = accelerator_get_status(); $config = accelerator_get_configuration(); $version = $config['version']['accelerator_product_name'] . ' ' . $config['version']['version']; $stats = $status['accelerator_statistics']; $hitrate = $stats['accelerator_hit_rate']; } $filelist = array(); if ($this->showFilelist) { foreach ($status['scripts'] as $key => $data) { $filelist[$key] = $data; $filelist[$key]['name'] = basename($key); } } // unset unneeded filelist to lower memory-usage unset($status['scripts']); $this->data = array('version' => $version, 'ini' => $config['directives'], 'filelist' => $filelist, 'status' => $status, 'stats' => $stats, 'hitrate' => $hitrate); }
/** * Constructor */ public function __construct() { if (extension_loaded('Zend OPcache')) { $this->_opCacheStats = opcache_get_status(); $this->_opCacheConfig = opcache_get_configuration(); } }
public function __construct($get_scripts = FALSE) { $this->statusData = opcache_get_status($get_scripts); if ($get_scripts) { $this->scripts = $this->statusData['scripts']; } }
/** * Whether or not PHP-OPcache is loaded and enabled * @return boolean true if loaded */ public static function opCacheEnabled() { if (!static::extOpCacheLoaded()) { return false; } $status = opcache_get_status(); return $status['opcache_enabled']; }
/** * @param string $path * * @return bool */ private function lintFile($path) { static $linter; if (empty($linter)) { $linter = !empty(opcache_get_status(false)['opcache_enabled']) ? [$this, 'opcacheLint'] : [$this, 'commandLineLint']; } return call_user_func($linter, $path); }
/** * Get OpCache status data * @param void * @access public * @return array */ public function status() { $status = null; if (function_exists('opcache_get_status')) { $status = opcache_get_status(); } return $status; }
public function opcode() { $i = opcache_get_status(); var_dump($i); $file = '/vagrant/simplephpmvc/Caches/test.php'; // $v = opcache_compile_file($file); // var_dump($v); // $v2 = opcache_is_script_cached($file); var_dump($v2); }
public function __construct() { if (!function_exists('opcache_compile_file')) { throw new \Exception("The OpCache extension isn't available!"); } $status = opcache_get_status(true); $this->memory = $status['memory_usage']; $this->statistics = $status['opcache_statistics']; $this->scripts = $status['scripts']; }
/** * Perform the check * * @see \ZendDiagnostics\Check\CheckInterface::check() * * @return Failure|Skip|Success|Warning */ public function check() { if (!function_exists('opcache_get_status')) { return new Warning('Zend OPcache extension is not available'); } $this->opCacheInfo = opcache_get_status(false); if (!is_array($this->opCacheInfo) || !array_key_exists('memory_usage', $this->opCacheInfo)) { return new Warning('Zend OPcache extension is not enabled in this environment'); } return parent::check(); }
public function __construct() { if (!extension_loaded('Zend OPcache')) { $this->_opcacheEnabled = false; } else { $this->_opcacheEnabled = true; } if ($this->_opcacheEnabled) { $this->_configuration = opcache_get_configuration(); $this->_status = opcache_get_status(); } }
/** * Removes files from the opcache. This assumes that the files still * exist on the instance in a previous checkout. * * @return int */ public function doClean() { $status = opcache_get_status(true); $filter = new StaleFiles($status['scripts'], $this->path); $files = $filter->filter(); foreach ($files as $file) { $status = opcache_invalidate($file['full_path'], true); if (false === $status) { $this->log(sprintf('Could not validate "%s".', $file['full_path']), 'error'); } } return 0; }
public function getStatusDataRows() { $stats = opcache_get_status(); foreach ($stats as $key => $val) { if (is_array($val)) { foreach ($val as $k => $v) { echo $k; echo ':'; echo $v; echo ';'; } } } }
function opcache_is_script_cached($file) { if (\extension_loaded('Zend OPCache')) { $opcached_files = opcache_get_status(); if (array_key_exists('scripts', $opcached_files)) { foreach ($opcached_files['scripts'] as $cache_file) { $fullpath = $cache_file['full_path']; if (normalize_pathfile($fullpath) == normalize_pathfile($file)) { return true; } } } return false; } return false; }
public function getIndex() { if (!$this->checkAccessRead()) { return; } /* * Check if Laravel is compiled to one single file */ $filename = app('path.base') . '/bootstrap/cache/compiled.php'; if (File::exists($filename)) { $optimized = '1 - ' . trans('app.compiled') . ': ' . Carbon::createFromTimeStamp(filemtime($filename)); } else { $optimized = 0; } /* * Count disabled modules */ $moduleBase = app()['modules']; $disabled = sizeof($moduleBase->disabled()); /* * Create array with names and values */ $placeholder = Config::get('app.key') == '01234567890123456789012345678912'; $appClass = get_class(app()); $opcacheExists = (int) function_exists('opcache_get_status'); $opcacheEnabled = $opcacheExists and opcache_get_status()['opcache_enabled'] ? 1 : 0; $settings = ['PHP.version' => phpversion(), 'PHP.os' => PHP_OS, 'PHP.ini' => php_ini_loaded_file(), 'PHP.memory_limit' => ini_get('memory_limit'), 'PHP.max_execution_time' => ini_get('max_execution_time'), 'PHP.post_max_size' => ini_get('post_max_size'), 'PHP.upload_max_filesize' => ini_get('upload_max_filesize'), 'Laravel.version' => $appClass::VERSION, 'Artisan optimized' => $optimized, 'App.environment' => App::environment(), 'App.url' => Config::get('app.url'), 'App.debug' => (int) Config::get('app.debug'), 'App.key' => $placeholder ? '<em>' . trans('app.placeholder') . '</em>' : trans('app.valid'), 'Cache.default' => Config::get('cache.default'), 'Modules.disabled' => $disabled, 'Mail.pretend' => (int) Config::get('mail.pretend'), 'OPcache.installed' => $opcacheExists, 'OPcache.enabled' => $opcacheEnabled, 'Xdebug.enabled' => extension_loaded('xdebug') ? 1 : 0]; /* * If we use MySQL as database, add values of some MySQL variables. */ if (Config::get('database.default') == 'mysql') { $fetchMethod = Config::get('database.fetch'); DB::connection()->setFetchMode(PDO::FETCH_ASSOC); // We need to get the result as array of arrays $sqlVars = DB::select('SHOW VARIABLES'); DB::connection()->setFetchMode($fetchMethod); $settings['MySQL.max_connections'] = $this->getSqlVar($sqlVars, 'max_connections'); $settings['MySQL.max_user_connections'] = $this->getSqlVar($sqlVars, 'max_user_connections'); } $this->pageView('diag::admin_index', compact('settings')); }
protected function clearOpcache() { $console = $this->getConsole(); if (!(bool) ini_get('opcache.enable_cli')) { $console->writeLine('You must enable opcache in CLI before clearing opcode cache', Color::RED); $console->writeLine('Check the "opcache.enable_cli" setting in your php.ini (see http://www.php.net/opcache.configuration)'); return; } $scripts = opcache_get_status(true)['scripts']; if (count($scripts) === 0) { $console->writeLine('No files cached in OPcache, aborting', Color::RED); return; } foreach (array_keys($scripts) as $file) { $result = opcache_invalidate($file, true); if (!$result) { $console->writeLine('Failed to clear opcode cache for ' . $file, Color::RED); } } $console->writeLine(sprintf('%s OPcache files cleared', count($scripts)), Color::GREEN); }
public function status($with_scripts = false) { // Guard execution if the extension is not loaded. if (!extension_loaded("Zend OPcache")) { return json_encode([]); } // Clear out data from prevous run $this->result['status'] = null; $raw = \opcache_get_status($with_scripts); // The scripts output has a really non-optimal format // for JSON, the result is a hash with the full path // as the key. Let's strip the key and turn it into // a regular array. if ($with_scripts == true) { // Make a copy of the raw scripts and then strip it from // the data. $scripts = $raw['scripts']; unset($raw['scripts']); $this->result['scripts'] = []; // Loop over each script and strip the key. foreach ($scripts as $key => $val) { $this->result['scripts'][] = $val; } // Sort by memory consumption usort($this->result['scripts'], function ($a, $b) { if ($a["memory_consumption"] == $b["memory_consumption"]) { return 0; } return $a["memory_consumption"] < $b["memory_consumption"] ? 1 : -1; }); } $this->result['status'] = $raw; if ($this->statsd != null) { $this->send_to_statsd(); } return json_encode($this->result); }
static function run() { if ('upgrader_process_complete' != current_filter()) { // only clear opcache on core updates return false; } error_log('pl5 - run() at ' . __CLASS__); if (!function_exists('opcache_reset')) { return false; } if (!function_exists('opcache_get_configuration')) { error_log('OPCache is not installed/running'); return false; } $data = opcache_get_status(); $expired = array(); if (empty($data['scripts'])) { error_log('no cached files'); return false; } error_log(count($data['scripts']) . ' cached'); foreach ($data['scripts'] as $file) { /* Added testing to see if timestamp was set - if not, opcache.revalidate_timestamp is off */ if (empty($file['timestamp'])) { error_log("This script only works if opcache.validate_timestamps is true in php.ini"); return false; } if (!empty($file['timestamp']) && !empty($file['full_path']) && (!file_exists($file['full_path']) || (int) $file['timestamp'] < filemtime($file['full_path']))) { $expired[] = $file['full_path']; opcache_invalidate($file['full_path'], true); } } error_log(count($expired) . ' deleted'); opcache_reset(); error_log('pl5 - cleared Opcache caches.'); }
<?php $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; $alias = 'phar://' . $fname; $phar = new Phar($fname); $phar['a.php'] = '<?php echo "This is a\\n"; ?>'; $phar['b.php'] = '<?php echo "This is b\\n"; ?>'; $phar['b/c.php'] = '<?php echo "This is b/c\\n"; ?>'; $phar->setStub('<?php __HALT_COMPILER(); ?>'); $phar->stopBuffering(); if (function_exists("opcache_get_status")) { $status = opcache_get_status(); if ($status["opcache_enabled"]) { ini_set("opcache.revalidate_freq", "0"); sleep(2); } } include $alias . '/a.php'; include $alias . '/b.php'; include $alias . '/b/c.php'; unlink($alias . '/b/c.php'); ?> ===AFTER=== <?php include $alias . '/a.php'; include $alias . '/b.php'; include $alias . '/b/c.php'; ?> ===DONE=== <?php
/** * Gets content panel for the Debug Bar * * @return string */ public function getPanel() { $panel = ''; $linebreak = $this->getLinebreak(); # Support for APC if (function_exists('apc_sma_info') && ini_get('apc.enabled')) { $mem = apc_sma_info(); $memSize = $mem['num_seg'] * $mem['seg_size']; $memAvail = $mem['avail_mem']; $memUsed = $memSize - $memAvail; $cache = apc_cache_info(); $numEntries = isset($cache['num_entries']) ? $cache['num_entries'] : 0; $numHits = isset($cache['num_hits']) ? $cache['num_hits'] : 0; $numMisses = isset($cache['num_misses']) ? $cache['num_misses'] : 0; $expunges = isset($cache['expunges']) ? $cache['expunges'] : ''; if ($cache['mem_size'] > 0) { $panel .= '<h4>APC ' . phpversion('apc') . ' Enabled</h4>'; $panel .= round($memAvail / 1024 / 1024, 1) . 'M available, ' . round($memUsed / 1024 / 1024, 1) . 'M used' . $linebreak . $numEntries . ' Files cached (' . round($cache['mem_size'] / 1024 / 1024, 1) . 'M)' . $linebreak . $numHits . ' Hits (' . round($numHits * 100 / ($numHits + $numMisses), 1) . '%)' . $linebreak . $expunges . ' Expunges (cache full count)'; } } if (function_exists('opcache_get_configuration')) { $opconfig = opcache_get_configuration(); if ($opconfig['directives']['opcache.enable']) { $opstatus = opcache_get_status(); $cache = $opstatus['opcache_statistics']; $panel .= '<h4>' . $opconfig['version']['opcache_product_name'] . ' ' . $opconfig['version']['version'] . ' Enabled</h4>'; $panel .= round($opstatus['memory_usage']['used_memory'] / 1024 / 1024, 1) . 'M used, ' . round($opstatus['memory_usage']['free_memory'] / 1024 / 1024, 1) . 'M free (' . round($opstatus['memory_usage']['current_wasted_percentage'], 1) . '% wasted)' . $linebreak . $cache['num_cached_scripts'] . ' Files cached' . $linebreak . $cache['hits'] . ' Hits (' . round($cache['opcache_hit_rate'], 1) . '%)'; } } /** @var \Zend_Cache_Backend_ExtendedInterface $backend */ foreach ($this->cacheBackends as $name => $backend) { $fillingPercentage = $backend->getFillingPercentage(); $ids = $backend->getIds(); # Print full class name, backends might be custom $panel .= '<h4>Cache ' . $name . ' (' . get_class($backend) . ')</h4>'; $panel .= count($ids) . ' Entr' . (count($ids) > 1 ? 'ies' : 'y') . '' . $linebreak . 'Filling Percentage: ' . $fillingPercentage . '%' . $linebreak; $cacheSize = 0; foreach ($ids as $id) { # Calculate valid cache size $memPre = memory_get_usage(); if ($cached = $backend->load($id)) { $memPost = memory_get_usage(); $cacheSize += $memPost - $memPre; unset($cached); } } $panel .= 'Valid Cache Size: ' . round($cacheSize / 1024, 1) . 'K'; } // adds form to clear the cache $panel .= '<h4>Clear cache</h4>' . $linebreak . '<form method="post"><button name="clear_cache" type="submit" class="btn">Clear cache</button></form>'; return $panel; }
protected function compileState() { $status = opcache_get_status(); $config = opcache_get_configuration(); $files = []; if (!empty($status['scripts'])) { uasort($status['scripts'], function ($a, $b) { return $a['hits'] < $b['hits']; }); foreach ($status['scripts'] as &$file) { $file['full_path'] = str_replace('\\', '/', $file['full_path']); $file['readable'] = ['hits' => number_format($file['hits']), 'memory_consumption' => $this->size($file['memory_consumption'])]; } $files = array_values($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' => $this->size($config['directives']['opcache.memory_consumption']), 'used_memory' => $this->size($status['memory_usage']['used_memory']), 'free_memory' => $this->size($status['memory_usage']['free_memory']), 'wasted_memory' => $this->size($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')]]); $directives = []; ksort($config['directives']); foreach ($config['directives'] as $k => $v) { $directives[] = ['k' => $k, 'v' => $v]; } $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' => $files, 'directives' => $directives, 'blacklist' => $config['blacklist'], 'functions' => get_extension_funcs('Zend OPcache')]; }
/** * @file * Initiates a browser-based installation of Drupal. */ // Change the directory to the Drupal root. chdir('..'); /** * Global flag to indicate the site is in installation mode. * * The constant is defined using define() instead of const so that PHP * versions prior to 5.3 can display proper PHP requirements instead of causing * a fatal error. */ define('MAINTENANCE_MODE', 'install'); // Exit early if running an incompatible PHP version to avoid fatal errors. // The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not // yet available. It is defined in bootstrap.inc, but it is not possible to // load that file yet as it would cause a fatal error on older versions of PHP. if (version_compare(PHP_VERSION, '5.5.9') < 0) { print 'Your PHP installation is too old. Drupal requires at least PHP 5.5.9. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.'; exit; } if (function_exists('opcache_get_status') && opcache_get_status()['opcache_enabled'] && !ini_get('opcache.save_comments')) { print 'Systems with OPcache installed must have <a href="http://php.net/manual/en/opcache.configuration.php#ini.opcache.save-comments">opcache.save_comments</a> enabled.'; exit; } // Start the installer. $class_loader = (require_once 'autoload.php'); require_once __DIR__ . '/includes/install.core.inc'; install_drupal($class_loader);
<?php # Get current date and time. $date_now = gmdate('D, d M Y H:i:s \\G\\M\\T'); # Send Headers header('Content-Type: application/json'); header("Expires: " . $date_now); header('Last-Modified: ' . $date_now); header('Cache-Control: max-age=0, no-cache, ' . 'must-revalidate, proxy-revalidate, ' . 'pre-check=0, post-check=0'); if (function_exists('opcache_get_status')) { $opcinfo = opcache_get_status(); unset($opcinfo['scripts']); echo json_encode($opcinfo); }
<?php namespace WebSharks\Ubuntu\Bootstrap; // @codingStandardsIgnoreFile // No strict types. This must be compatible w/ PHP v5.4+. // i.e., This is used by the WordPress dev containers. error_reporting(-1); ini_set('display_errors', 'yes'); header('content-type: text/plain; charset=utf-8'); print_r(opcache_get_status());
<?php /** * Part of Munin PHP OPcache plugin - Refer to php_opcache for installation instructions. */ if (function_exists('opcache_get_status')) { $data = opcache_get_status(); $output = array('mem_used.value' => $data['memory_usage']['used_memory'], 'mem_free.value' => $data['memory_usage']['free_memory'], 'mem_wasted.value' => $data['memory_usage']['wasted_memory']); } else { // OPCache not installed :( $output = array('mem_used.value' => 0, 'mem_free.value' => 0); } header('Content-Type: text/plain'); foreach ($output as $key => $value) { echo $key, ' ', $value, "\n"; }
/** * Show settings of the module * * @global object $objTemplate * @global array $_ARRAYLANG */ function showSettings() { global $objTemplate, $_ARRAYLANG; $this->objTpl->loadTemplateFile('settings.html'); $this->objTpl->setVariable(array('TXT_CACHE_GENERAL' => $_ARRAYLANG['TXT_SETTINGS_MENU_CACHE'], 'TXT_CACHE_STATS' => $_ARRAYLANG['TXT_CACHE_STATS'], 'TXT_CACHE_CONTREXX_CACHING' => $_ARRAYLANG['TXT_CACHE_CONTREXX_CACHING'], 'TXT_CACHE_USERCACHE' => $_ARRAYLANG['TXT_CACHE_USERCACHE'], 'TXT_CACHE_OPCACHE' => $_ARRAYLANG['TXT_CACHE_OPCACHE'], 'TXT_CACHE_PROXYCACHE' => $_ARRAYLANG['TXT_CACHE_PROXYCACHE'], 'TXT_CACHE_EMPTY' => $_ARRAYLANG['TXT_CACHE_EMPTY'], 'TXT_CACHE_STATS' => $_ARRAYLANG['TXT_CACHE_STATS'], 'TXT_CACHE_APC' => $_ARRAYLANG['TXT_CACHE_APC'], 'TXT_CACHE_ZEND_OPCACHE' => $_ARRAYLANG['TXT_CACHE_ZEND_OPCACHE'], 'TXT_CACHE_XCACHE' => $_ARRAYLANG['TXT_CACHE_XCACHE'], 'TXT_CACHE_MEMCACHE' => $_ARRAYLANG['TXT_CACHE_MEMCACHE'], 'TXT_CACHE_MEMCACHED' => $_ARRAYLANG['TXT_CACHE_MEMCACHED'], 'TXT_CACHE_FILESYSTEM' => $_ARRAYLANG['TXT_CACHE_FILESYSTEM'], 'TXT_CACHE_APC_ACTIVE_INFO' => $_ARRAYLANG['TXT_CACHE_APC_ACTIVE_INFO'], 'TXT_CACHE_APC_CONFIG_INFO' => $_ARRAYLANG['TXT_CACHE_APC_CONFIG_INFO'], 'TXT_CACHE_ZEND_OPCACHE_ACTIVE_INFO' => $_ARRAYLANG['TXT_CACHE_ZEND_OPCACHE_ACTIVE_INFO'], 'TXT_CACHE_ZEND_OPCACHE_CONFIG_INFO' => $_ARRAYLANG['TXT_CACHE_ZEND_OPCACHE_CONFIG_INFO'], 'TXT_CACHE_XCACHE_ACTIVE_INFO' => $_ARRAYLANG['TXT_CACHE_XCACHE_ACTIVE_INFO'], 'TXT_CACHE_XCACHE_CONFIG_INFO' => $_ARRAYLANG['TXT_CACHE_XCACHE_CONFIG_INFO'], 'TXT_CACHE_MEMCACHE_ACTIVE_INFO' => $_ARRAYLANG['TXT_CACHE_MEMCACHE_ACTIVE_INFO'], 'TXT_CACHE_MEMCACHE_CONFIG_INFO' => $_ARRAYLANG['TXT_CACHE_MEMCACHE_CONFIG_INFO'], 'TXT_CACHE_MEMCACHED_ACTIVE_INFO' => $_ARRAYLANG['TXT_CACHE_MEMCACHED_ACTIVE_INFO'], 'TXT_CACHE_MEMCACHED_CONFIG_INFO' => $_ARRAYLANG['TXT_CACHE_MEMCACHED_CONFIG_INFO'], 'TXT_CACHE_ENGINE' => $_ARRAYLANG['TXT_CACHE_ENGINE'], 'TXT_CACHE_INSTALLATION_STATE' => $_ARRAYLANG['TXT_CACHE_INSTALLATION_STATE'], 'TXT_CACHE_ACTIVE_STATE' => $_ARRAYLANG['TXT_CACHE_ACTIVE_STATE'], 'TXT_CACHE_CONFIGURATION_STATE' => $_ARRAYLANG['TXT_CACHE_CONFIGURATION_STATE'], 'TXT_SETTINGS_SAVE' => $_ARRAYLANG['TXT_SAVE'], 'TXT_SETTINGS_ON' => $_ARRAYLANG['TXT_ACTIVATED'], 'TXT_SETTINGS_OFF' => $_ARRAYLANG['TXT_DEACTIVATED'], 'TXT_SETTINGS_STATUS' => $_ARRAYLANG['TXT_CACHE_SETTINGS_STATUS'], 'TXT_SETTINGS_STATUS_HELP' => $_ARRAYLANG['TXT_CACHE_SETTINGS_STATUS_HELP'], 'TXT_SETTINGS_EXPIRATION' => $_ARRAYLANG['TXT_CACHE_SETTINGS_EXPIRATION'], 'TXT_SETTINGS_EXPIRATION_HELP' => $_ARRAYLANG['TXT_CACHE_SETTINGS_EXPIRATION_HELP'], 'TXT_EMPTY_BUTTON' => $_ARRAYLANG['TXT_CACHE_EMPTY'], 'TXT_EMPTY_DESC' => $_ARRAYLANG['TXT_CACHE_EMPTY_DESC'], 'TXT_EMPTY_DESC_APC' => $_ARRAYLANG['TXT_CACHE_EMPTY_DESC_FILES_AND_ENRIES'], 'TXT_EMPTY_DESC_ZEND_OP' => $_ARRAYLANG['TXT_CACHE_EMPTY_DESC_FILES'], 'TXT_EMPTY_DESC_MEMCACHE' => $_ARRAYLANG['TXT_CACHE_EMPTY_DESC_MEMCACHE'], 'TXT_EMPTY_DESC_XCACHE' => $_ARRAYLANG['TXT_CACHE_EMPTY_DESC_FILES_AND_ENRIES'], 'TXT_STATS_FILES' => $_ARRAYLANG['TXT_CACHE_STATS_FILES'], 'TXT_STATS_FOLDERSIZE' => $_ARRAYLANG['TXT_CACHE_STATS_FOLDERSIZE'], 'TXT_STATS_CHACHE_SITE_COUNT' => $_ARRAYLANG['TXT_STATS_CHACHE_SITE_COUNT'], 'TXT_STATS_CHACHE_ENTRIES_COUNT' => $_ARRAYLANG['TXT_STATS_CHACHE_ENTRIES_COUNT'], 'TXT_STATS_CACHE_SIZE' => $_ARRAYLANG['TXT_STATS_CACHE_SIZE'], 'TXT_DEACTIVATED' => $_ARRAYLANG['TXT_DEACTIVATED'], 'TXT_DISPLAY_CONFIGURATION' => $_ARRAYLANG['TXT_DISPLAY_CONFIGURATION'], 'TXT_HIDE_CONFIGURATION' => $_ARRAYLANG['TXT_HIDE_CONFIGURATION'])); $this->objTpl->setVariable($_ARRAYLANG); if ($this->objSettings->isWritable()) { $this->objTpl->parse('cache_submit_button'); } else { $this->objTpl->hideBlock('cache_submit_button'); $objTemplate->SetVariable('CONTENT_STATUS_MESSAGE', implode("<br />\n", $this->objSettings->strErrMessage)); } // parse op cache engines $this->parseOPCacheEngines(); // parse user cache engines $this->parseUserCacheEngines(); $this->parseMemcacheSettings(); $this->parseMemcachedSettings(); $this->parseReverseProxySettings(); $this->parseSsiProcessorSettings(); $intFoldersizePages = 0; $intFoldersizeEntries = 0; $intFilesPages = 0; $intFilesEntries = 0; $handleFolder = opendir($this->strCachePath); if ($handleFolder) { while ($strFile = readdir($handleFolder)) { if ($strFile != '.' && $strFile != '..') { if (is_dir($this->strCachePath . '/' . $strFile)) { $intFoldersizeEntries += filesize($this->strCachePath . $strFile); ++$intFilesEntries; } elseif ($strFile !== '.htaccess') { $intFoldersizePages += filesize($this->strCachePath . $strFile); ++$intFilesPages; } } } $intFoldersizeEntries = filesize($this->strCachePath) - $intFoldersizePages - filesize($this->strCachePath . '.htaccess'); closedir($handleFolder); } if ($this->isInstalled(self::CACHE_ENGINE_APC) && $this->isConfigured(self::CACHE_ENGINE_APC) && ($this->opCacheEngine == self::CACHE_ENGINE_APC || $this->userCacheEngine == self::CACHE_ENGINE_APC)) { $this->objTpl->touchBlock('apcCachingStats'); $apcSmaInfo = \apc_sma_info(); $apcCacheInfo = \apc_cache_info(); } else { $this->objTpl->hideBlock('apcCachingStats'); } if ($this->isInstalled(self::CACHE_ENGINE_ZEND_OPCACHE) && $this->isConfigured(self::CACHE_ENGINE_ZEND_OPCACHE) && $this->opCacheEngine == self::CACHE_ENGINE_ZEND_OPCACHE && $this->getOpCacheActive()) { $this->objTpl->touchBlock('zendOpCachingStats'); $opCacheConfig = \opcache_get_configuration(); $opCacheStatus = \opcache_get_status(); } else { $this->objTpl->hideBlock('zendOpCachingStats'); } if ($this->isInstalled(self::CACHE_ENGINE_MEMCACHE) && $this->isConfigured(self::CACHE_ENGINE_MEMCACHE) && $this->userCacheEngine == self::CACHE_ENGINE_MEMCACHE && $this->getUserCacheActive()) { $this->objTpl->touchBlock('memcacheCachingStats'); $memcacheStats = $this->memcache->getStats(); } else { $this->objTpl->hideBlock('memcacheCachingStats'); } if ($this->isInstalled(self::CACHE_ENGINE_MEMCACHED) && $this->isConfigured(self::CACHE_ENGINE_MEMCACHED) && $this->userCacheEngine == self::CACHE_ENGINE_MEMCACHED && $this->getUserCacheActive()) { $this->objTpl->touchBlock('memcachedCachingStats'); $memcachedStats = $this->memcached->getStats(); } else { $this->objTpl->hideBlock('memcachedCachingStats'); } if ($this->isInstalled(self::CACHE_ENGINE_XCACHE) && $this->isConfigured(self::CACHE_ENGINE_XCACHE) && ($this->opCacheEngine == self::CACHE_ENGINE_XCACHE || $this->userCacheEngine == self::CACHE_ENGINE_XCACHE)) { $this->objTpl->touchBlock('xCacheCachingStats'); } else { $this->objTpl->hideBlock('xCacheCachingStats'); } if ($this->userCacheEngine == self::CACHE_ENGINE_FILESYSTEM && $this->getUserCacheActive()) { $this->objTpl->touchBlock('FileSystemCachingStats'); } else { $this->objTpl->hideBlock('FileSystemCachingStats'); } $apcSizeCount = isset($apcCacheInfo['nhits']) ? $apcCacheInfo['nhits'] : 0; $apcEntriesCount = 0; if (isset($apcCacheInfo)) { foreach ($apcCacheInfo['cache_list'] as $entity) { if (false !== strpos($entity['key'], $this->getCachePrefix())) { $apcEntriesCount++; } } } $apcMaxSizeKb = isset($apcSmaInfo['num_seg']) && isset($apcSmaInfo['seg_size']) ? $apcSmaInfo['num_seg'] * $apcSmaInfo['seg_size'] / 1024 : 0; $apcSizeKb = isset($apcCacheInfo['mem_size']) ? $apcCacheInfo['mem_size'] / 1024 : 0; $opcacheSizeCount = !isset($opCacheStatus) || $opCacheStatus == false ? 0 : $opCacheStatus['opcache_statistics']['num_cached_scripts']; $opcacheSizeKb = (!isset($opCacheStatus) || $opCacheStatus == false ? 0 : $opCacheStatus['memory_usage']['used_memory']) / (1024 * 1024); $opcacheMaxSizeKb = isset($opCacheConfig['directives']['opcache.memory_consumption']) ? $opCacheConfig['directives']['opcache.memory_consumption'] / (1024 * 1024) : 0; $memcacheEntriesCount = isset($memcacheStats['curr_items']) ? $memcacheStats['curr_items'] : 0; $memcacheSizeMb = isset($memcacheStats['bytes']) ? $memcacheStats['bytes'] / (1024 * 1024) : 0; $memcacheMaxSizeMb = isset($memcacheStats['limit_maxbytes']) ? $memcacheStats['limit_maxbytes'] / (1024 * 1024) : 0; $memcacheConfiguration = $this->getMemcacheConfiguration(); $memcacheServerKey = $memcacheConfiguration['ip'] . ':' . $memcacheConfiguration['port']; $memcachedServerEntriesCount = isset($memcachedStats[$memcacheServerKey]['curr_items']) ? $memcachedStats[$memcacheServerKey]['curr_items'] : 0; $memcachedServerSizeMb = isset($memcachedStats[$memcacheServerKey]['bytes']) ? $memcachedStats[$memcacheServerKey]['bytes'] / (1024 * 1024) : 0; $memcachedEntriesCount = $this->getMemcachedEntryCount(); $memcachedSizeMb = $memcachedServerEntriesCount ? $memcachedServerSizeMb / $memcachedServerEntriesCount * $memcachedEntriesCount : 0; $memcachedMaxSizeMb = isset($memcachedStats[$memcacheServerKey]['limit_maxbytes']) ? $memcachedStats[$memcacheServerKey]['limit_maxbytes'] / (1024 * 1024) : 0; $this->objTpl->setVariable(array('SETTINGS_STATUS_ON' => $this->arrSettings['cacheEnabled'] == 'on' ? 'checked' : '', 'SETTINGS_STATUS_OFF' => $this->arrSettings['cacheEnabled'] == 'off' ? 'checked' : '', 'SETTINGS_OP_CACHE_STATUS_ON' => $this->arrSettings['cacheOpStatus'] == 'on' ? 'checked' : '', 'SETTINGS_OP_CACHE_STATUS_OFF' => $this->arrSettings['cacheOpStatus'] == 'off' ? 'checked' : '', 'SETTINGS_DB_CACHE_STATUS_ON' => $this->arrSettings['cacheDbStatus'] == 'on' ? 'checked' : '', 'SETTINGS_DB_CACHE_STATUS_OFF' => $this->arrSettings['cacheDbStatus'] == 'off' ? 'checked' : '', 'SETTINGS_CACHE_REVERSE_PROXY_NONE' => $this->arrSettings['cacheReverseProxy'] == 'none' ? 'selected' : '', 'SETTINGS_CACHE_REVERSE_PROXY_VARNISH' => $this->arrSettings['cacheReverseProxy'] == 'varnish' ? 'selected' : '', 'SETTINGS_CACHE_REVERSE_PROXY_NGINX' => $this->arrSettings['cacheReverseProxy'] == 'nginx' ? 'selected' : '', 'SETTINGS_SSI_CACHE_STATUS_INTERN' => $this->arrSettings['cacheSsiOutput'] == 'intern' ? 'selected' : '', 'SETTINGS_SSI_CACHE_STATUS_SSI' => $this->arrSettings['cacheSsiOutput'] == 'ssi' ? 'selected' : '', 'SETTINGS_SSI_CACHE_STATUS_ESI' => $this->arrSettings['cacheSsiOutput'] == 'esi' ? 'selected' : '', 'INTERNAL_SSI_CACHE_ON' => $this->arrSettings['internalSsiCache'] == 'on' ? 'checked' : '', 'INTERNAL_SSI_CACHE_OFF' => $this->arrSettings['internalSsiCache'] != 'on' ? 'checked' : '', 'SETTINGS_SSI_CACHE_TYPE_VARNISH' => $this->arrSettings['cacheSsiType'] == 'varnish' ? 'selected' : '', 'SETTINGS_SSI_CACHE_TYPE_NGINX' => $this->arrSettings['cacheSsiType'] == 'nginx' ? 'selected' : '', 'SETTINGS_EXPIRATION' => intval($this->arrSettings['cacheExpiration']), 'STATS_CONTREXX_FILESYSTEM_CHACHE_PAGES_COUNT' => $intFilesPages, 'STATS_FOLDERSIZE_PAGES' => number_format($intFoldersizePages / 1024, 2, '.', '\''), 'STATS_CONTREXX_FILESYSTEM_CHACHE_ENTRIES_COUNT' => $intFilesEntries, 'STATS_FOLDERSIZE_ENTRIES' => number_format($intFoldersizeEntries / 1024, 2, '.', '\''), 'STATS_APC_CHACHE_SITE_COUNT' => $apcSizeCount, 'STATS_APC_CHACHE_ENTRIES_COUNT' => $apcEntriesCount, 'STATS_APC_MAX_SIZE' => number_format($apcMaxSizeKb, 2, '.', '\''), 'STATS_APC_SIZE' => number_format($apcSizeKb, 2, '.', '\''), 'STATS_OPCACHE_CHACHE_SITE_COUNT' => $opcacheSizeCount, 'STATS_OPCACHE_SIZE' => number_format($opcacheSizeKb, 2, '.', '\''), 'STATS_OPCACHE_MAX_SIZE' => number_format($opcacheMaxSizeKb, 2, '.', '\''), 'STATS_MEMCACHE_CHACHE_ENTRIES_COUNT' => $memcacheEntriesCount, 'STATS_MEMCACHE_SIZE' => number_format($memcacheSizeMb, 2, '.', '\''), 'STATS_MEMCACHE_MAX_SIZE' => number_format($memcacheMaxSizeMb, 2, '.', '\''), 'STATS_MEMCACHED_CHACHE_ENTRIES_COUNT' => $memcachedEntriesCount, 'STATS_MEMCACHED_SIZE' => number_format($memcachedSizeMb, 2, '.', '\''), 'STATS_MEMCACHED_MAX_SIZE' => number_format($memcachedMaxSizeMb, 2, '.', '\''))); $objTemplate->setVariable(array('CONTENT_TITLE' => $_ARRAYLANG['TXT_SETTINGS_MENU_CACHE'], 'ADMIN_CONTENT' => $this->objTpl->get())); }
/** * Display a report about system performance * - opcode cache (opcache) * - user data cache (apcu / apcu-bc) * * @since 9.1 **/ function showPerformanceInformations() { global $CFG_GLPI; if (!Config::canUpdate()) { return false; } echo "<div class='center' id='tabsbody'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . __('PHP opcode cache') . "</th></tr>"; $ext = 'Zend OPcache'; if (extension_loaded($ext) && ($info = opcache_get_status(false))) { echo "<tr><td>" . sprintf(__('The "%s" extension is installed'), $ext) . "</td>\n <td>" . phpversion($ext) . "</td>\n <td></td>\n <td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt='{$ext}'></td></tr>"; // echo "<tr><td><pre>".print_r($info, true)."</pre></td></tr>"; // Memory $used = $info['memory_usage']['used_memory']; $free = $info['memory_usage']['free_memory']; $rate = round(100.0 * $used / ($used + $free)); $max = Toolbox::getSize($used + $free); $used = Toolbox::getSize($used); echo "<tr><td>" . __('Memory') . "</td>\n <td>" . sprintf(__('%1$s / %2$s'), $used, $max) . "</td><td>"; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo "</td><td><img src='" . $CFG_GLPI['root_doc'] . "/pics/" . ($rate > 5 && $rate < 75 ? 'ok_min.png' : 'ko_min.png') . "' alt='{$ext}'></td></tr>"; // Hits $hits = $info['opcache_statistics']['hits']; $miss = $info['opcache_statistics']['misses']; $max = $hits + $miss; $rate = round($info['opcache_statistics']['opcache_hit_rate']); echo "<tr><td>" . __('Hits rate') . "</td>\n <td>" . sprintf(__('%1$s / %2$s'), $hits, $max) . "</td><td>"; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo "</td><td><img src='" . $CFG_GLPI['root_doc'] . "/pics/" . ($rate > 90 ? 'ok_min.png' : 'ko_min.png') . "' alt='{$ext}'></td></tr>"; // Restart (1 seems ok, can happen) $max = $info['opcache_statistics']['oom_restarts']; echo "<tr><td>" . __('Out of memory restart') . "</td>\n <td>{$max}</td><td>"; echo "</td><td><img src='" . $CFG_GLPI['root_doc'] . "/pics/" . ($max < 2 ? 'ok_min.png' : 'ko_min.png') . "' alt='{$ext}'></td></tr>"; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { echo "<tr><td></td><td colspan='3'>"; echo "<a class='vsubmit' href='config.form.php?reset_opcache=1'>"; _e('Reset'); echo "</a></td></tr>\n"; } } else { echo "<tr><td>" . sprintf(__('Installing and enabling the "%s" extension may improve GLPI performance'), $ext) . "</td>\n <td></td>\n <td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png' alt='{$ext}'></td></tr>"; } echo "<tr><th colspan='4'>" . __('User data cache') . "</th></tr>"; $ext = PHP_MAJOR_VERSION < 7 ? 'APCu' : 'apcu-bc'; if (function_exists('apc_fetch')) { echo "<tr><td>" . sprintf(__('The "%s" extension is installed'), $ext) . "</td>\n <td>" . phpversion('apc') . "</td>\n <td></td>\n <td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt='{$ext}'></td></tr>"; $info = apc_sma_info(true); $stat = apc_cache_info('user', true); // echo "<tr><td><pre>Info:".print_r($info, true)."Stat:".print_r($stat, true)."</pre></td></tr>"; // Memory $max = $info['num_seg'] * $info['seg_size']; $free = $info['avail_mem']; $used = $max - $free; $rate = round(100.0 * $used / $max); $max = Toolbox::getSize($used + $free); $used = Toolbox::getSize($used); echo "<tr><td>" . __('Memory') . "</td>\n <td>" . sprintf(__('%1$s / %2$s'), $used, $max) . "</td><td>"; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo "</td><td><img src='" . $CFG_GLPI['root_doc'] . "/pics/" . ($rate > 5 && $rate < 50 ? 'ok_min.png' : 'ko_min.png') . "' alt='{$ext}'></td></tr>"; // Hits $hits = $stat['num_hits']; $miss = $stat['num_misses']; $max = $hits + $miss; $rate = round(100 * $hits / ($hits + $miss)); echo "<tr><td>" . __('Hits rate') . "</td>\n <td>" . sprintf(__('%1$s / %2$s'), $hits, $max) . "</td><td>"; Html::displayProgressBar('100', $rate, array('simple' => true, 'forcepadding' => false)); echo "</td><td><img src='" . $CFG_GLPI['root_doc'] . "/pics/" . ($rate > 90 ? 'ok_min.png' : 'ko_min.png') . "' alt='{$ext}'></td></tr>"; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { echo "<tr><td></td><td colspan='3'>"; echo "<a class='vsubmit' href='config.form.php?reset_apcu=1'>"; _e('Reset'); echo "</a></td></tr>\n"; } } else { echo "<tr><td>" . sprintf(__('Installing the "%s" extension may improve GLPI performance'), $ext) . "</td>\n <td></td>\n <td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png' alt='{$ext}'></td></tr>"; } echo "</table></div>\n"; }
if (substr($file, strlen($file) - 4) == ".php") { $files[] = $fullPath; } } } } return $files; } echo '--------------------------<br>'; echo 'Очищаем старый кэш...'; // opcache_reset(); echo 'OK<br>'; echo '--------------------------<br>'; echo '--------------------------<br>'; echo 'Статус кэша:<br>'; var_dump(opcache_get_status()); echo '--------------------------<br>'; $foldersToLoad = array("_core", "_modules"); $coreFolder = str_replace("_bootstrap.php", "", __FILE__); echo '--------------------------<br>'; echo 'Загружаем:<br>'; foreach ($foldersToLoad as $folder) { foreach (preload($folder) as $file) { echo $file; if (@opcache_compile_file($file)) { echo '...<font color="green">OK</font><br>'; } else { echo '...<font color="red">FAILED</font><br>'; } } }