5 $fatal_exception = null;
7 PhabricatorStartup
::beginStartupPhase('libraries');
8 PhabricatorStartup
::loadCoreLibraries();
10 PhabricatorStartup
::beginStartupPhase('purge');
11 PhabricatorCaches
::destroyRequestCache();
13 PhabricatorStartup
::beginStartupPhase('sink');
14 $sink = new AphrontPHPHTTPSink();
16 // PHP introduced a "Throwable" interface in PHP 7 and began making more
17 // runtime errors throw as "Throwable" errors. This is generally good, but
18 // makes top-level exception handling that is compatible with both PHP 5
19 // and PHP 7 a bit tricky.
21 // In PHP 5, "Throwable" does not exist, so "catch (Throwable $ex)" catches
24 // In PHP 7, various runtime conditions raise an Error which is a Throwable
25 // but NOT an Exception, so "catch (Exception $ex)" will not catch them.
27 // To cover both cases, we "catch (Exception $ex)" to catch everything in
28 // PHP 5, and most things in PHP 7. Then, we "catch (Throwable $ex)" to catch
29 // everything else in PHP 7. For the most part, we only need to do this at
32 $main_exception = null;
34 PhabricatorStartup
::beginStartupPhase('run');
35 AphrontApplicationConfiguration
::runHTTPRequest($sink);
36 } catch (Exception
$ex) {
37 $main_exception = $ex;
38 } catch (Throwable
$ex) {
39 $main_exception = $ex;
42 if ($main_exception) {
43 $response_exception = null;
45 $response = new AphrontUnhandledExceptionResponse();
46 $response->setException($main_exception);
47 $response->setShowStackTraces($sink->getShowStackTraces());
49 PhabricatorStartup
::endOutputCapture();
50 $sink->writeResponse($response);
51 } catch (Exception
$ex) {
52 $response_exception = $ex;
53 } catch (Throwable
$ex) {
54 $response_exception = $ex;
57 // If we hit a rendering exception, ignore it and throw the original
58 // exception. It is generally more interesting and more likely to be
61 if ($response_exception) {
62 throw $main_exception;
65 } catch (Exception
$ex) {
66 $fatal_exception = $ex;
67 } catch (Throwable
$ex) {
68 $fatal_exception = $ex;
71 if ($fatal_exception) {
72 PhabricatorStartup
::didEncounterFatalException(
78 function phabricator_startup() {
79 // Load the PhabricatorStartup class itself.
80 $t_startup = microtime(true);
81 $root = dirname(dirname(__FILE__
));
82 require_once $root.'/support/startup/PhabricatorStartup.php';
84 // Load client limit classes so the preamble can configure limits.
85 require_once $root.'/support/startup/PhabricatorClientLimit.php';
86 require_once $root.'/support/startup/PhabricatorClientRateLimit.php';
87 require_once $root.'/support/startup/PhabricatorClientConnectionLimit.php';
88 require_once $root.'/support/startup/preamble-utils.php';
90 // If the preamble script exists, load it.
91 $t_preamble = microtime(true);
92 $preamble_path = $root.'/support/preamble.php';
93 if (file_exists($preamble_path)) {
94 require_once $preamble_path;
97 $t_hook = microtime(true);
98 PhabricatorStartup
::didStartup($t_startup);
100 PhabricatorStartup
::recordStartupPhase('startup.init', $t_startup);
101 PhabricatorStartup
::recordStartupPhase('preamble', $t_preamble);
102 PhabricatorStartup
::recordStartupPhase('hook', $t_hook);