diff --git a/core/includes/install.inc b/core/includes/install.inc
index 895f068..4fa63df 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -307,6 +307,14 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
     if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) {
       throw new Exception(t('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
     }
+    else {
+      // 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.
+      // @see \Drupal\simpletest\WebTestBase::setUp()
+      if (function_exists('opcache_invalidate')) {
+        opcache_invalidate(DRUPAL_ROOT . '/' . $settings_file, TRUE);
+      }
+    }
   }
   else {
     throw new Exception(t('Failed to open %settings. Verify the file permissions.', array('%settings' => $settings_file)));
