diff --git a/support/PhabricatorStartup.php b/support/PhabricatorStartup.php index 5b0d266e97..cf4b0d09d3 100644 --- a/support/PhabricatorStartup.php +++ b/support/PhabricatorStartup.php @@ -17,6 +17,7 @@ final class PhabricatorStartup { private static $startTime; private static $globals = array(); + private static $capturingOutput; /* -( Accessing Request Information )-------------------------------------- */ @@ -78,6 +79,8 @@ final class PhabricatorStartup { self::verifyRewriteRules(); self::detectPostMaxSizeTriggered(); + + self::beginOutputCapture(); } @@ -149,6 +152,26 @@ final class PhabricatorStartup { phutil_load_library($phabricator_root.'/src'); } +/* -( Output Capture )----------------------------------------------------- */ + + + public static function beginOutputCapture() { + if (self::$capturingOutput) { + self::didFatal("Already capturing output!"); + } + self::$capturingOutput = true; + ob_start(); + } + + + public static function endOutputCapture() { + if (!self::$capturingOutput) { + return null; + } + self::$capturingOutput = false; + return ob_get_clean(); + } + /* -( In Case of Apocalypse )---------------------------------------------- */ @@ -157,6 +180,7 @@ final class PhabricatorStartup { * @task apocalypse */ public static function didFatal($message) { + self::endOutputCapture(); $access_log = self::getGlobal('log.access'); if ($access_log) { diff --git a/webroot/index.php b/webroot/index.php index c6af0494f7..7221ded949 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -30,6 +30,7 @@ try { $response = PhabricatorSetupCheck::willProcessRequest(); if ($response) { + PhabricatorStartup::endOutputCapture(); $sink->writeResponse($response); return; } @@ -102,8 +103,21 @@ try { $response = $application->willSendResponse($response, $controller); $response->setRequest($request); - $sink->writeResponse($response); + $unexpected_output = PhabricatorStartup::endOutputCapture(); + if ($unexpected_output) { + $unexpected_output = "Unexpected output:\n\n{$unexpected_output}"; + phlog($unexpected_output); + if ($response instanceof AphrontWebpageResponse) { + echo hsprintf( + '
%s
', + $unexpected_output); + } + } + + $sink->writeResponse($response); } catch (Exception $ex) { $write_guard->dispose(); if ($access_log) {