diff --git a/core/includes/install.inc b/core/includes/install.inc index 066884c..6df05bf 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\OpCache; use Drupal\Component\Utility\Settings; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; @@ -165,52 +166,6 @@ function drupal_get_database_types() { } /** - * Flushes a PHP file from any active opcode cache. - * - * If it is not possible to flush an individual file, the whole cache will be - * flushed. - * - * @param string $filepath - * Filepath of PHP file to be flushed. - * - * @throws Exception - */ -function drupal_clear_opcode_cache($filepath) { - // This setting can be On/Off or 1/0, but when the setting is Off - // the returned value is an empty string instead of 0. - $empty_values = array("", 0); - clearstatcache(TRUE, $filepath); - - try { - if (extension_loaded('Zend OPcache')) { - $timestamps = ini_get('opcache.validate_timestamps'); - if (!$timestamps || ($timestamps && ini_get('opcache.revalidate_freq') != 0)) { - opcache_invalidate($filepath); - } - } - if (extension_loaded('apc') && in_array(ini_get('apc.stat'), $empty_values)) { - apc_delete_file($filepath); - } - if (extension_loaded('wincache')) { - if (in_array(ini_get('wincache.fcndetect'), $empty_values) || ini_get('wincache.chkinterval') == 0) { - wincache_refresh_if_changed(array($filepath)); - } - } - if (extension_loaded('XCache') && in_array(ini_get('xcache.stat'), $empty_values)) { - for ($i = 0; $i < xcache_count(XC_TYPE_PHP); $i++) { - xcache_clear_cache(XC_TYPE_PHP, $i); - } - } - if (extension_loaded('eaccelerator')) { - eaccelerator_clear(); - } - } - catch (Exception $e) { - throw new Exception(t('Failed to clear the opcode cache for %file. For the duration of the installation it is recommended to either disable the opcode cache, or reconfigure it to allow code changes to be seen immediately.', array('%file' => $filepath))); - } -} - -/** * Replaces values in settings.php with values in the submitted array. * * This function replaces values in place if possible, even for @@ -370,13 +325,11 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { $old_settings = Settings::getAll(); new Settings($settings_settings + $old_settings); } - - // Since the existing PHP file is rewritten, ensure that PHP's opcache is - // aware of the new content, in case the file is included again or if the - // opcode cache doesn't check the script on each request to determine if - // it has been modified. - // @see \Drupal\simpletest\WebTestBase::setUp() - drupal_clear_opcode_cache(DRUPAL_ROOT . '/' . $settings_file); + // The existing settings.php file might have been included already. In + // case an opcode cache is enabled, the rewritten contents of the file + // will not be reflected in this process. Ensure to invalidate the file + // in case an opcode cache is enabled. + OpCache::invalidate(DRUPAL_ROOT . '/' . $settings_file); } } else { diff --git a/core/lib/Drupal/Component/Utility/OpCache.php b/core/lib/Drupal/Component/Utility/OpCache.php new file mode 100644 index 0000000..1a88e1f --- /dev/null +++ b/core/lib/Drupal/Component/Utility/OpCache.php @@ -0,0 +1,51 @@ +