* Use $_SERVER['REQUEST_TIME_FLOAT'] unconditionally in WebRequest.php
and libs/Timing.php. WebStart.php was doing this already without issue.
The key existst since PHP 5.4, for both Web and CLI (we require 5.5).
* In wfDebug() and wfReportTime(), use $_SERVER['REQUEST_TIME_FLOAT'] instead.
* In ApiFormatBase and MWDebug, use WebRequest::getElapsedTime() instead.
* In Maintenance.php, remove setting of $wgRequestTime.
* In rebuildFileCache.php, update mocking to $_SERVER['REQUEST_TIME_FLOAT']
so that we avoid re-introducing bug T24852.
Change-Id: I1b647da2862f815029caa533b592ec8a05b33806
*/
function wfDebug( $text, $dest = 'all', array $context = [] ) {
global $wgDebugRawPage, $wgDebugLogPrefix;
*/
function wfDebug( $text, $dest = 'all', array $context = [] ) {
global $wgDebugRawPage, $wgDebugLogPrefix;
- global $wgDebugTimestamps, $wgRequestTime;
+ global $wgDebugTimestamps;
if ( !$wgDebugRawPage && wfIsDebugRawPage() ) {
return;
if ( !$wgDebugRawPage && wfIsDebugRawPage() ) {
return;
if ( $wgDebugTimestamps ) {
$context['seconds_elapsed'] = sprintf(
'%6.4f',
if ( $wgDebugTimestamps ) {
$context['seconds_elapsed'] = sprintf(
'%6.4f',
- microtime( true ) - $wgRequestTime
+ microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT']
);
$context['memory_used'] = sprintf(
'%5.1fM',
);
$context['memory_used'] = sprintf(
'%5.1fM',
* @return string
*/
function wfReportTime() {
* @return string
*/
function wfReportTime() {
- global $wgRequestTime, $wgShowHostnames;
+ global $wgShowHostnames;
- $responseTime = round( ( microtime( true ) - $wgRequestTime ) * 1000 );
+ $elapsed = ( microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'] );
+ // seconds to milliseconds
+ $responseTime = round( $elapsed * 1000 );
$reportVars = [ 'wgBackendResponseTime' => $responseTime ];
if ( $wgShowHostnames ) {
$reportVars['wgHostname'] = wfHostname();
$reportVars = [ 'wgBackendResponseTime' => $responseTime ];
if ( $wgShowHostnames ) {
$reportVars['wgHostname'] = wfHostname();
* @codeCoverageIgnore
*/
public function __construct() {
* @codeCoverageIgnore
*/
public function __construct() {
- $this->requestTime = isset( $_SERVER['REQUEST_TIME_FLOAT'] )
- ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true );
+ $this->requestTime = $_SERVER['REQUEST_TIME_FLOAT'];
// POST overrides GET data
// We don't use $_REQUEST here to avoid interference from cookies...
// POST overrides GET data
// We don't use $_REQUEST here to avoid interference from cookies...
if ( $this->getIsWrappedHtml() ) {
// This is a special output mode mainly intended for ApiSandbox use
if ( $this->getIsWrappedHtml() ) {
// This is a special output mode mainly intended for ApiSandbox use
- $time = microtime( true ) - $this->getConfig()->get( 'RequestTime' );
+ $time = $this->getMain()->getRequest()->getElapsedTime();
$json = FormatJson::encode(
[
'status' => (int)( $this->mHttpStatus ?: 200 ),
$json = FormatJson::encode(
[
'status' => (int)( $this->mHttpStatus ?: 200 ),
- global $wgVersion, $wgRequestTime;
$request = $context->getRequest();
// HHVM's reported memory usage from memory_get_peak_usage()
$request = $context->getRequest();
// HHVM's reported memory usage from memory_get_peak_usage()
'gitRevision' => GitInfo::headSHA1(),
'gitBranch' => $branch,
'gitViewUrl' => GitInfo::headViewUrl(),
'gitRevision' => GitInfo::headSHA1(),
'gitBranch' => $branch,
'gitViewUrl' => GitInfo::headViewUrl(),
- 'time' => microtime( true ) - $wgRequestTime,
+ 'time' => $request->getElapsedTime(),
'log' => self::$log,
'debugLog' => self::$debug,
'queries' => self::$query,
'log' => self::$log,
'debugLog' => self::$debug,
'queries' => self::$query,
'requestStart' => [
'name' => 'requestStart',
'entryType' => 'mark',
'requestStart' => [
'name' => 'requestStart',
'entryType' => 'mark',
- 'startTime' => isset( $_SERVER['REQUEST_TIME_FLOAT'] )
- ? $_SERVER['REQUEST_TIME_FLOAT']
- : $_SERVER['REQUEST_TIME'],
+ 'startTime' => $_SERVER['REQUEST_TIME_FLOAT'],
* Do some sanity checking and basic setup
*/
public function setup() {
* Do some sanity checking and basic setup
*/
public function setup() {
- global $IP, $wgCommandLineMode, $wgRequestTime;
+ global $IP, $wgCommandLineMode;
# Abort if called from a web server
# wfIsCLI() is not available yet
# Abort if called from a web server
# wfIsCLI() is not available yet
# But sometimes this doesn't seem to be the case.
ini_set( 'max_execution_time', 0 );
# But sometimes this doesn't seem to be the case.
ini_set( 'max_execution_time', 0 );
- $wgRequestTime = microtime( true );
-
# Define us as being in MediaWiki
define( 'MEDIAWIKI', true );
# Define us as being in MediaWiki
define( 'MEDIAWIKI', true );
}
public function execute() {
}
public function execute() {
- global $wgRequestTime;
-
if ( !$this->enabled ) {
$this->fatalError( "Nothing to do -- \$wgUseFileCache is disabled." );
}
if ( !$this->enabled ) {
$this->fatalError( "Nothing to do -- \$wgUseFileCache is disabled." );
}
$this->fatalError( "Nothing to do." );
}
$this->fatalError( "Nothing to do." );
}
- $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
+ // Mock request (hack, no real client)
+ $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip';
# Do remaining chunk
$end += $batchSize - 1;
# Do remaining chunk
$end += $batchSize - 1;
}
Wikimedia\suppressWarnings(); // header notices
}
Wikimedia\suppressWarnings(); // header notices
- // Cache ?action=view
- $wgRequestTime = microtime( true ); # T24852
+
+ // 1. Cache ?action=view
+ // Be sure to reset the mocked request time (T24852)
+ $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true );
ob_start();
$article->view();
$context->getOutput()->output();
$context->getOutput()->clearHTML();
$viewHtml = ob_get_clean();
$viewCache->saveToFileCache( $viewHtml );
ob_start();
$article->view();
$context->getOutput()->output();
$context->getOutput()->clearHTML();
$viewHtml = ob_get_clean();
$viewCache->saveToFileCache( $viewHtml );
- // Cache ?action=history
- $wgRequestTime = microtime( true ); # T24852
+
+ // 2. Cache ?action=history
+ // Be sure to reset the mocked request time (T24852)
+ $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true );
ob_start();
Action::factory( 'history', $article, $context )->show();
$context->getOutput()->output();
$context->getOutput()->clearHTML();
$historyHtml = ob_get_clean();
$historyCache->saveToFileCache( $historyHtml );
ob_start();
Action::factory( 'history', $article, $context )->show();
$context->getOutput()->output();
$context->getOutput()->clearHTML();
$historyHtml = ob_get_clean();
$historyCache->saveToFileCache( $historyHtml );
Wikimedia\restoreWarnings();
if ( $rebuilt ) {
Wikimedia\restoreWarnings();
if ( $rebuilt ) {
public function testDetectServer( $expected, $input, $description ) {
$this->setMwGlobals( 'wgAssumeProxiesUseDefaultProtocolPorts', true );
public function testDetectServer( $expected, $input, $description ) {
$this->setMwGlobals( 'wgAssumeProxiesUseDefaultProtocolPorts', true );
+ $this->setServerVars( $input );
$result = WebRequest::detectServer();
$this->assertEquals( $expected, $result, $description );
}
$result = WebRequest::detectServer();
$this->assertEquals( $expected, $result, $description );
}
* @covers WebRequest::getIP
*/
public function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) {
* @covers WebRequest::getIP
*/
public function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) {
+ $this->setServerVars( $input );
$this->setMwGlobals( [
'wgUsePrivateIPs' => $private,
'wgHooks' => [
$this->setMwGlobals( [
'wgUsePrivateIPs' => $private,
'wgHooks' => [
* @covers WebRequest::getAcceptLang
*/
public function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) {
* @covers WebRequest::getAcceptLang
*/
public function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) {
- $_SERVER = [ 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ];
+ $this->setServerVars( [ 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ] );
$request = new WebRequest();
$this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description );
}
$request = new WebRequest();
$this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description );
}
+
+ protected function setServerVars( $vars ) {
+ // Don't remove vars which should be available in all SAPI.
+ if ( !isset( $vars['REQUEST_TIME_FLOAT'] ) ) {
+ $vars['REQUEST_TIME_FLOAT'] = $_SERVER['REQUEST_TIME_FLOAT'];
+ }
+ if ( !isset( $vars['REQUEST_TIME'] ) ) {
+ $vars['REQUEST_TIME'] = $_SERVER['REQUEST_TIME'];
+ }
+ $_SERVER = $vars;
+ }