diff --git a/includes/install.inc b/includes/install.inc index 71de3e6..ff1d847 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -582,6 +582,29 @@ class DatabaseTaskException extends Exception { } /** + * Invalidates a PHP file from a possibly active opcode cache. + * + * In case the opcode cache does not support to invalidate an individual file, + * the entire cache will be flushed. + * + * @param string $pathname + * The absolute pathname of the PHP file to invalidate. + */ +function drupal_clear_opcode_cache($pathname) { + clearstatcache(TRUE, $pathname); + + if (extension_loaded('Zend OPcache')) { + opcache_invalidate($pathname, TRUE); + } + if (extension_loaded('apc')) { + // apc_delete_file() throws a PHP warning in case the specified file was + // not compiled yet. + // @see http://php.net/manual/en/function.apc-delete-file.php + @apc_delete_file($pathname); + } +} + +/** * Replaces values in settings.php with values in the submitted array. * * @param $settings @@ -653,6 +676,13 @@ function drupal_rewrite_settings($settings = array(), $prefix = '') { if ($fp && fwrite($fp, $buffer) === FALSE) { throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file))); } + else { + // 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. + drupal_clear_opcode_cache(DRUPAL_ROOT . '/' . $settings_file); + } } else { throw new Exception(st('Failed to open %settings. Verify the file permissions.', array('%settings' => $default_settings)));