Changeset View
Changeset View
Standalone View
Standalone View
support/PhabricatorStartup.php
| Show All 28 Lines | |||||
| * Users are allowed to accumulate up to 1000 points per minute, averaged across | * Users are allowed to accumulate up to 1000 points per minute, averaged across | ||||
| * all of the tracked buckets. | * all of the tracked buckets. | ||||
| * | * | ||||
| * @task info Accessing Request Information | * @task info Accessing Request Information | ||||
| * @task hook Startup Hooks | * @task hook Startup Hooks | ||||
| * @task apocalypse In Case Of Apocalypse | * @task apocalypse In Case Of Apocalypse | ||||
| * @task validation Validation | * @task validation Validation | ||||
| * @task ratelimit Rate Limiting | * @task ratelimit Rate Limiting | ||||
| * @task phases Startup Phase Timers | |||||
| */ | */ | ||||
| final class PhabricatorStartup { | final class PhabricatorStartup { | ||||
| private static $startTime; | private static $startTime; | ||||
| private static $debugTimeLimit; | private static $debugTimeLimit; | ||||
| private static $accessLog; | private static $accessLog; | ||||
| private static $capturingOutput; | private static $capturingOutput; | ||||
| private static $rawInput; | private static $rawInput; | ||||
| private static $oldMemoryLimit; | private static $oldMemoryLimit; | ||||
| private static $phases; | |||||
| // TODO: For now, disable rate limiting entirely by default. We need to | // TODO: For now, disable rate limiting entirely by default. We need to | ||||
| // iterate on it a bit for Conduit, some of the specific score levels, and | // iterate on it a bit for Conduit, some of the specific score levels, and | ||||
| // to deal with NAT'd offices. | // to deal with NAT'd offices. | ||||
| private static $maximumRate = 0; | private static $maximumRate = 0; | ||||
| /* -( Accessing Request Information )-------------------------------------- */ | /* -( Accessing Request Information )-------------------------------------- */ | ||||
| Show All 30 Lines | public static function getRawInput() { | ||||
| return self::$rawInput; | return self::$rawInput; | ||||
| } | } | ||||
| /* -( Startup Hooks )------------------------------------------------------ */ | /* -( Startup Hooks )------------------------------------------------------ */ | ||||
| /** | /** | ||||
| * @param float Request start time, from `microtime(true)`. | |||||
| * @task hook | * @task hook | ||||
| */ | */ | ||||
| public static function didStartup() { | public static function didStartup($start_time) { | ||||
| self::$startTime = microtime(true); | self::$startTime = $start_time; | ||||
| self::$phases = array(); | |||||
| self::$accessLog = null; | self::$accessLog = null; | ||||
| static $registered; | static $registered; | ||||
| if (!$registered) { | if (!$registered) { | ||||
| // NOTE: This protects us against multiple calls to didStartup() in the | // NOTE: This protects us against multiple calls to didStartup() in the | ||||
| // same request, but also against repeated requests to the same | // same request, but also against repeated requests to the same | ||||
| // interpreter state, which we may implement in the future. | // interpreter state, which we may implement in the future. | ||||
| register_shutdown_function(array(__CLASS__, 'didShutdown')); | register_shutdown_function(array(__CLASS__, 'didShutdown')); | ||||
| ▲ Show 20 Lines • Show All 745 Lines • ▼ Show 20 Lines | header( | ||||
| $replace = true, | $replace = true, | ||||
| $http_error = 429); | $http_error = 429); | ||||
| echo $message; | echo $message; | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| /* -( Startup Timers )----------------------------------------------------- */ | |||||
| /** | |||||
| * Record the beginning of a new startup phase. | |||||
| * | |||||
| * For phases which occur before @{class:PhabricatorStartup} loads, save the | |||||
| * time and record it with @{method:recordStartupPhase} after the class is | |||||
| * available. | |||||
| * | |||||
| * @param string Phase name. | |||||
| * @task phases | |||||
| */ | |||||
| public static function beginStartupPhase($phase) { | |||||
| self::recordStartupPhase($phase, microtime(true)); | |||||
| } | |||||
| /** | |||||
| * Record the start time of a previously executed startup phase. | |||||
| * | |||||
| * For startup phases which occur after @{class:PhabricatorStartup} loads, | |||||
| * use @{method:beginStartupPhase} instead. This method can be used to | |||||
| * record a time before the class loads, then hand it over once the class | |||||
| * becomes available. | |||||
| * | |||||
| * @param string Phase name. | |||||
| * @param float Phase start time, from `microtime(true)`. | |||||
| * @task phases | |||||
| */ | |||||
| public static function recordStartupPhase($phase, $time) { | |||||
| self::$phases[$phase] = $time; | |||||
| } | |||||
| /** | |||||
| * Get information about startup phase timings. | |||||
| * | |||||
| * Sometimes, performance problems can occur before we start the profiler. | |||||
| * Since the profiler can't examine these phases, it isn't useful in | |||||
| * understanding their performance costs. | |||||
| * | |||||
| * Instead, the startup process marks when it enters various phases using | |||||
| * @{method:beginStartupPhase}. A later call to this method can retrieve this | |||||
| * information, which can be examined to gain greater insight into where | |||||
| * time was spent. The output is still crude, but better than nothing. | |||||
| * | |||||
| * @task phases | |||||
| */ | |||||
| public static function getPhases() { | |||||
| return self::$phases; | |||||
| } | |||||
| } | } | ||||