From c32b474cb88d1069fe5b8f653eded179bc11129b Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Mon, 1 Aug 2016 12:42:23 +0100 Subject: [PATCH] Issue #2639878 by RobLoach, omega8cc, memtkmcc: Use less demanding check to see if OPcache is active --- core/install.php | 9 +++++++-- core/lib/Drupal/Component/Utility/OpCodeCache.php | 10 ++++++++++ core/modules/system/system.install | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/install.php b/core/install.php index 50deb38f8fa..6bdd6f8c315 100644 --- a/core/install.php +++ b/core/install.php @@ -5,6 +5,8 @@ * Initiates a browser-based installation of Drupal. */ +use Drupal\Component\Utility\OpCodeCache; + // Change the directory to the Drupal root. chdir('..'); // Store the Drupal root path. @@ -28,12 +30,15 @@ if (version_compare(PHP_VERSION, '5.5.9') < 0) { exit; } -if (function_exists('opcache_get_status') && opcache_get_status()['opcache_enabled'] && !ini_get('opcache.save_comments')) { +// Initialize the autoloader. +$class_loader = require_once $root_path . '/autoload.php'; + +// If OPCache is in use, ensure opcache.save_comments is enabled. +if (OpCodeCache::isEnabled() && !ini_get('opcache.save_comments')) { print 'Systems with OPcache installed must have opcache.save_comments enabled.'; exit(); } // Start the installer. -$class_loader = require_once $root_path . '/autoload.php'; require_once $root_path . '/core/includes/install.core.inc'; install_drupal($class_loader); diff --git a/core/lib/Drupal/Component/Utility/OpCodeCache.php b/core/lib/Drupal/Component/Utility/OpCodeCache.php index d53874a06f0..efce6f2b00d 100644 --- a/core/lib/Drupal/Component/Utility/OpCodeCache.php +++ b/core/lib/Drupal/Component/Utility/OpCodeCache.php @@ -9,6 +9,16 @@ namespace Drupal\Component\Utility; */ class OpCodeCache { + /** + * Checks if OpCodeCache is enabled. + * + * @return bool + * TRUE if opcache is enabled, FALSE otherwise. + */ + public static function isEnabled() { + return extension_loaded('Zend OPcache') && ini_get('opcache.enable'); + } + /** * Invalidates a PHP file from a possibly active opcode cache. * diff --git a/core/modules/system/system.install b/core/modules/system/system.install index b3a0ec1d1c9..ed181f27879 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -7,6 +7,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Environment; +use Drupal\Component\Utility\OpCodeCache; use Drupal\Core\Path\AliasStorage; use Drupal\Core\Url; use Drupal\Core\Database\Database; @@ -242,8 +243,7 @@ function system_requirements($phase) { if ($phase == 'install' || $phase == 'runtime') { // Check to see if OPcache is installed. - $opcache_enabled = (function_exists('opcache_get_status') && opcache_get_status()['opcache_enabled']); - if (!$opcache_enabled) { + if (!OpCodeCache::isEnabled()) { $requirements['php_opcache'] = array( 'value' => t('Not enabled'), 'severity' => REQUIREMENT_WARNING,