@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 103 lines 3.3 kB view raw
1<?php 2 3phabricator_startup(); 4 5$fatal_exception = null; 6try { 7 PhabricatorStartup::beginStartupPhase('libraries'); 8 PhabricatorStartup::loadCoreLibraries(); 9 10 PhabricatorStartup::beginStartupPhase('purge'); 11 PhabricatorCaches::destroyRequestCache(); 12 13 PhabricatorStartup::beginStartupPhase('sink'); 14 $sink = new AphrontPHPHTTPSink(); 15 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. 20 21 // In PHP 5, "Throwable" does not exist, so "catch (Throwable $ex)" catches 22 // nothing. 23 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. 26 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 30 // the top level. 31 32 $main_exception = null; 33 try { 34 PhabricatorStartup::beginStartupPhase('run'); 35 AphrontApplicationConfiguration::runHTTPRequest($sink); 36 } catch (Exception $ex) { 37 $main_exception = $ex; 38 } catch (Throwable $ex) { 39 $main_exception = $ex; 40 } 41 42 if ($main_exception) { 43 $response_exception = null; 44 try { 45 $response = new AphrontUnhandledExceptionResponse(); 46 $response->setException($main_exception); 47 $response->setShowStackTraces($sink->getShowStackTraces()); 48 49 PhabricatorStartup::endOutputCapture(); 50 $sink->writeResponse($response); 51 } catch (Exception $ex) { 52 $response_exception = $ex; 53 } catch (Throwable $ex) { 54 $response_exception = $ex; 55 } 56 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 59 // the root cause. 60 61 if ($response_exception) { 62 throw $main_exception; 63 } 64 } 65} catch (Exception $ex) { 66 $fatal_exception = $ex; 67} catch (Throwable $ex) { 68 $fatal_exception = $ex; 69} 70 71if ($fatal_exception) { 72 PhabricatorStartup::didEncounterFatalException( 73 'Core Exception', 74 $fatal_exception, 75 false); 76} 77 78function 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'; 83 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'; 89 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; 95 } 96 97 $t_hook = microtime(true); 98 PhabricatorStartup::didStartup($t_startup); 99 100 PhabricatorStartup::recordStartupPhase('startup.init', $t_startup); 101 PhabricatorStartup::recordStartupPhase('preamble', $t_preamble); 102 PhabricatorStartup::recordStartupPhase('hook', $t_hook); 103}