diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index b11a8c88048df370d01267b2a51306d45057f0d8..86d80dbdd145252273f7bf67998cb8508b35e87f 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -1403,8 +1403,10 @@ function _drupal_bootstrap($phase) {
       }
 
       // Prepare for non-cached page workflow.
-      ob_start();
-      drupal_page_header();
+      if ($_SERVER['SERVER_SOFTWARE'] !== 'PHP CLI') {
+        ob_start();
+        drupal_page_header();
+      }
       break;
 
     case DRUPAL_BOOTSTRAP_LANGUAGE:
diff --git a/includes/common.inc b/includes/common.inc
index e4400995ebb696c4b08fd27134da5b620ae4d013..e1e2053d6341220850410ac2dde4752b3cfabeac 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -834,7 +834,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
   }
 
   if ($fatal) {
-    drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' 500 Service unavailable (with message)');
+    drupal_set_header('500 Service unavailable (with message)');
   }
 
   if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
diff --git a/modules/simpletest/tests/error.test b/modules/simpletest/tests/error.test
index ed430bfff262b7f086a4fa3ee9ccc542a92eaa26..b98c38cc8b7c7f50205cf558b49642fc0031d807 100644
--- a/modules/simpletest/tests/error.test
+++ b/modules/simpletest/tests/error.test
@@ -46,6 +46,7 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
     // Set error reporting to collect notices.
     variable_set('error_level', ERROR_REPORTING_DISPLAY_ALL);
     $this->drupalGet('error-test/generate-warnings');
+    $this->assertResponse(200, t('Received expected HTTP status code.'));
     $this->assertErrorMessage($error_notice);
     $this->assertErrorMessage($error_warning);
     $this->assertErrorMessage($error_user_notice);
@@ -53,6 +54,7 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
     // Set error reporting to not collect notices.
     variable_set('error_level', ERROR_REPORTING_DISPLAY_SOME);
     $this->drupalGet('error-test/generate-warnings');
+    $this->assertResponse(200, t('Received expected HTTP status code.'));
     $this->assertNoErrorMessage($error_notice);
     $this->assertErrorMessage($error_warning);
     $this->assertErrorMessage($error_user_notice);
@@ -60,6 +62,7 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
     // Set error reporting to not show any errors.
     variable_set('error_level', ERROR_REPORTING_HIDE);
     $this->drupalGet('error-test/generate-warnings');
+    $this->assertResponse(200, t('Received expected HTTP status code.'));
     $this->assertNoErrorMessage($error_notice);
     $this->assertNoErrorMessage($error_warning);
     $this->assertNoErrorMessage($error_user_notice);
@@ -85,9 +88,11 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
     );
 
     $this->drupalGet('error-test/trigger-exception');
+    $this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), t('Received expected HTTP status line.'));
     $this->assertErrorMessage($error_exception);
 
     $this->drupalGet('error-test/trigger-pdo-exception');
+    $this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), t('Received expected HTTP status line.'));
     // We cannot use assertErrorMessage() since the extact error reported
     // varies from database to database. Check that the SQL string is displayed.
     $this->assertText($error_pdo_exception['%type'], t('Found %type in error page.', $error_pdo_exception));