diff --git a/core/includes/install.inc b/core/includes/install.inc index 74d8e39..8d93fa8 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -162,6 +162,47 @@ 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. + */ +function drupal_clear_opcode_cache($filepath) { + clearstatcache(TRUE, $filepath); + + try { + if (function_exists('opcache_invalidate')) { + $timestamps = ini_get('opcache.validate_timestamps'); + if (!$timestamps || ($timestamps && ini_get('opcache.revalidate_freq' != 0)) { + opcache_invalidate($filepath); + } + } + if (function_exists('apc_delete_file') && ini_get('apc.stat') == 0) { + apc_delete_file($filepath); + } + if (function_exists('wincache_refresh_if_changed')) { + if (ini_get('wincache.fcndetect') == 0 || ini_get('wincache.chkinterval') == 0) { + wincache_refresh_if_changed(array($filepath)); + } + } + if (function_exists('xcache_clear_cache')) { + // Use @ error suppression. + @xcache_clear_cache(XC_TYPE_PHP); + } + if (function_exists('eaccelerator_clear')) { + // Use @ error suppression. + @eaccelerator_clear(); + } + } + catch (Exception $e) { + throw new Exception(t('Failed to clear the opcode cache for %settings. 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('%settings' => $settings_file))); + } +} + +/** * Replaces values in settings.php with values in the submitted array. * * This function replaces values in place if possible, even for @@ -194,6 +235,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { if (!isset($settings_file)) { $settings_file = conf_path(FALSE) . '/settings.php'; } + $filepath = DRUPAL_ROOT . '/' . $settings_file; // Build list of setting names and insert the values into the global namespace. $variable_names = array(); $settings_settings = array(); @@ -206,7 +248,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { } $variable_names['$'. $setting] = $setting; } - $contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file); + $contents = file_get_contents($filepath); if ($contents !== FALSE) { // Step through each token in settings.php and replace any variables that // are in the passed-in array. @@ -307,7 +349,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { } // Write the new settings file. - if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) { + if (file_put_contents($filepath, $buffer) === FALSE) { throw new Exception(t('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file))); } else { @@ -322,6 +364,8 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { else { throw new Exception(t('Failed to open %settings. Verify the file permissions.', array('%settings' => $settings_file))); } + // Remove settings.php from any active opcode cache. + drupal_clear_opcode_cache($filepath); } /**