From c33f4de066c23d27f9011e8c9c1b7d9282485498 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 27 Feb 2015 09:08:06 -0800 Subject: [PATCH] Profile all external HTTP requests from MW Change-Id: Ie980b080da2ef21ec7d9fc32f1accc55710de140 --- includes/Import.php | 4 ++-- includes/externalstore/ExternalStoreHttp.php | 2 +- includes/filerepo/ForeignAPIRepo.php | 2 +- includes/filerepo/file/File.php | 2 +- includes/installer/Installer.php | 4 ++-- includes/jobqueue/jobs/ThumbnailRenderJob.php | 7 ++++--- includes/parser/Parser.php | 2 +- includes/site/MediaWikiSite.php | 2 +- includes/specials/SpecialUploadStash.php | 2 +- includes/upload/UploadFromUrl.php | 2 +- maintenance/benchmarks/bench_HTTP_HTTPS.php | 2 +- maintenance/findHooks.php | 2 +- maintenance/importImages.inc | 4 ++-- maintenance/importSiteScripts.php | 4 ++-- tests/phpunit/includes/HttpTest.php | 2 +- tests/phpunit/includes/api/ApiLoginTest.php | 3 ++- tests/phpunit/includes/filebackend/FileBackendTest.php | 2 +- 17 files changed, 25 insertions(+), 23 deletions(-) diff --git a/includes/Import.php b/includes/Import.php index c036fbecf1..3ba4306c65 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -1741,7 +1741,7 @@ class WikiRevision { // @todo FIXME! $src = $this->getSrc(); - $data = Http::get( $src ); + $data = Http::get( $src, array(), __METHOD__ ); if ( !$data ) { wfDebug( "IMPORT: couldn't fetch source $src\n" ); fclose( $f ); @@ -1898,7 +1898,7 @@ class ImportStreamSource implements ImportSource { # quicker and sorts out user-agent problems which might # otherwise prevent importing from large sites, such # as the Wikimedia cluster, etc. - $data = Http::request( $method, $url, array( 'followRedirects' => true ) ); + $data = Http::request( $method, $url, array( 'followRedirects' => true ), __METHOD__ ); if ( $data !== false ) { $file = tmpfile(); fwrite( $file, $data ); diff --git a/includes/externalstore/ExternalStoreHttp.php b/includes/externalstore/ExternalStoreHttp.php index 345c17be26..00030d8521 100644 --- a/includes/externalstore/ExternalStoreHttp.php +++ b/includes/externalstore/ExternalStoreHttp.php @@ -31,7 +31,7 @@ class ExternalStoreHttp extends ExternalStoreMedium { * @see ExternalStoreMedium::fetchFromURL() */ public function fetchFromURL( $url ) { - return Http::get( $url ); + return Http::get( $url, array(), __METHOD__ ); } /** diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 6924f0a6bb..7ead968fde 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -514,7 +514,7 @@ class ForeignAPIRepo extends FileRepo { $options['timeout'] = 'default'; } - $req = MWHttpRequest::factory( $url, $options ); + $req = MWHttpRequest::factory( $url, $options, __METHOD__ ); $req->setUserAgent( ForeignAPIRepo::getUserAgent() ); $status = $req->execute(); diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 6ca61b26b7..2721693461 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2008,7 +2008,7 @@ abstract class File { wfDebug( "miss\n" ); } wfDebug( "Fetching shared description from $renderUrl\n" ); - $res = Http::get( $renderUrl ); + $res = Http::get( $renderUrl, array(), __METHOD__ ); if ( $res && $this->repo->descriptionCacheExpiry > 0 ) { $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); } diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 91195e9144..c29b462b74 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -1375,7 +1375,7 @@ abstract class Installer { } try { - $text = Http::get( $url . $file, array( 'timeout' => 3 ) ); + $text = Http::get( $url . $file, array( 'timeout' => 3 ), __METHOD__ ); } catch ( Exception $e ) { // Http::get throws with allow_url_fopen = false and no curl extension. $text = null; @@ -1723,7 +1723,7 @@ abstract class Installer { if ( MWHttpRequest::canMakeRequests() ) { $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl, - array( 'method' => 'POST', 'postData' => $params ) )->execute(); + array( 'method' => 'POST', 'postData' => $params ), __METHOD__ )->execute(); if ( !$res->isOK() ) { $s->warning( 'config-install-subscribe-fail', $res->getMessage() ); } diff --git a/includes/jobqueue/jobs/ThumbnailRenderJob.php b/includes/jobqueue/jobs/ThumbnailRenderJob.php index dbc4f23ff8..4b5189d975 100644 --- a/includes/jobqueue/jobs/ThumbnailRenderJob.php +++ b/includes/jobqueue/jobs/ThumbnailRenderJob.php @@ -92,9 +92,10 @@ class ThumbnailRenderJob extends Job { wfDebug( __METHOD__ . ": hitting url {$thumbUrl}\n" ); - $request = MWHttpRequest::factory( $thumbUrl, array( - 'method' => 'HEAD', - 'followRedirects' => true ) ); + $request = MWHttpRequest::factory( $thumbUrl, + array( 'method' => 'HEAD', 'followRedirects' => true ), + __METHOD__ + ); if ( $wgUploadThumbnailRenderHttpCustomHost ) { $request->setHeader( 'Host', $wgUploadThumbnailRenderHttpCustomHost ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index a9b0c82c62..2f443c0164 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4096,7 +4096,7 @@ class Parser { return $obj->tc_contents; } - $req = MWHttpRequest::factory( $url ); + $req = MWHttpRequest::factory( $url, array(), __METHOD__ ); $status = $req->execute(); // Status object if ( $status->isOK() ) { $text = $req->getContent(); diff --git a/includes/site/MediaWikiSite.php b/includes/site/MediaWikiSite.php index 9711f04207..739d01812a 100644 --- a/includes/site/MediaWikiSite.php +++ b/includes/site/MediaWikiSite.php @@ -137,7 +137,7 @@ class MediaWikiSite extends Site { // Go on call the external site // @todo we need a good way to specify a timeout here. - $ret = Http::get( $url ); + $ret = Http::get( $url, array(), __METHOD__ ); } if ( $ret === false ) { diff --git a/includes/specials/SpecialUploadStash.php b/includes/specials/SpecialUploadStash.php index 462dbee833..4a92bb9f16 100644 --- a/includes/specials/SpecialUploadStash.php +++ b/includes/specials/SpecialUploadStash.php @@ -252,7 +252,7 @@ class SpecialUploadStash extends UnlistedSpecialPage { 'method' => 'GET', 'timeout' => 'default' ); - $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions ); + $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions, __METHOD__ ); $status = $req->execute(); if ( !$status->isOK() ) { $errors = $status->getErrorsArray(); diff --git a/includes/upload/UploadFromUrl.php b/includes/upload/UploadFromUrl.php index 3d410b1cb1..fc59ace541 100644 --- a/includes/upload/UploadFromUrl.php +++ b/includes/upload/UploadFromUrl.php @@ -287,7 +287,7 @@ class UploadFromUrl extends UploadBase { 'Starting download from "' . $this->mUrl . '" ' . '<' . implode( ',', array_keys( array_filter( $options ) ) ) . '>' ); - $req = MWHttpRequest::factory( $this->mUrl, $options ); + $req = MWHttpRequest::factory( $this->mUrl, $options, __METHOD__ ); $req->setCallback( array( $this, 'saveTempFileChunk' ) ); $status = $req->execute(); diff --git a/maintenance/benchmarks/bench_HTTP_HTTPS.php b/maintenance/benchmarks/bench_HTTP_HTTPS.php index bb7499b738..1569234865 100644 --- a/maintenance/benchmarks/bench_HTTP_HTTPS.php +++ b/maintenance/benchmarks/bench_HTTP_HTTPS.php @@ -46,7 +46,7 @@ class BenchHttpHttps extends Benchmarker { } static function doRequest( $proto ) { - Http::get( "$proto://localhost/" ); + Http::get( "$proto://localhost/", array(), __METHOD__ ); } // bench function 1 diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php index d17b06d663..5cf4536706 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -185,7 +185,7 @@ class FindHooks extends Maintenance { $retval = array(); while ( true ) { - $json = Http::get( wfAppendQuery( 'http://www.mediawiki.org/w/api.php', $params ) ); + $json = Http::get( wfAppendQuery( 'http://www.mediawiki.org/w/api.php', $params ), array(), __METHOD__ ); $data = FormatJson::decode( $json, true ); foreach ( $data['query']['categorymembers'] as $page ) { if ( preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $m ) ) { diff --git a/maintenance/importImages.inc b/maintenance/importImages.inc index b803e3dae4..4b839a0f8a 100644 --- a/maintenance/importImages.inc +++ b/maintenance/importImages.inc @@ -117,7 +117,7 @@ function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) { function getFileCommentFromSourceWiki( $wiki_host, $file ) { $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment'; - $body = Http::get( $url ); + $body = Http::get( $url, array(), __METHOD__ ); if ( preg_match( '##', $body, $matches ) == 0 ) { return false; } @@ -128,7 +128,7 @@ function getFileCommentFromSourceWiki( $wiki_host, $file ) { function getFileUserFromSourceWiki( $wiki_host, $file ) { $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user'; - $body = Http::get( $url ); + $body = Http::get( $url, array(), __METHOD__ ); if ( preg_match( '##', $body, $matches ) == 0 ) { return false; } diff --git a/maintenance/importSiteScripts.php b/maintenance/importSiteScripts.php index e67d07719c..6566a60d97 100644 --- a/maintenance/importSiteScripts.php +++ b/maintenance/importSiteScripts.php @@ -59,7 +59,7 @@ class ImportSiteScripts extends Maintenance { $url = wfAppendQuery( $baseUrl, array( 'action' => 'raw', 'title' => "MediaWiki:{$page}" ) ); - $text = Http::get( $url ); + $text = Http::get( $url, array(), __METHOD__ ); $wikiPage = WikiPage::factory( $title ); $content = ContentHandler::makeContent( $text, $wikiPage->getTitle() ); @@ -81,7 +81,7 @@ class ImportSiteScripts extends Maintenance { while ( true ) { $url = wfAppendQuery( $baseUrl, $data ); - $strResult = Http::get( $url ); + $strResult = Http::get( $url, array(), __METHOD__ ); $result = FormatJson::decode( $strResult, true ); $page = null; diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index e3ee7056cb..8a0dff786a 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -138,7 +138,7 @@ class HttpTest extends MediaWikiTestCase { * HTTP redirects). */ public function testRelativeRedirections() { - $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext' ); + $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext', array(), __METHOD__ ); # Forge a Location header $h->setRespHeaders( 'location', array( diff --git a/tests/phpunit/includes/api/ApiLoginTest.php b/tests/phpunit/includes/api/ApiLoginTest.php index 67a75f363f..88a99e9b16 100644 --- a/tests/phpunit/includes/api/ApiLoginTest.php +++ b/tests/phpunit/includes/api/ApiLoginTest.php @@ -123,7 +123,8 @@ class ApiLoginTest extends ApiTestCase { "lgname" => $user->username, "lgpassword" => $user->password ) - ) + ), + __METHOD__ ); $req->execute(); diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index b40d2d213e..bfca75ad6f 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -1478,7 +1478,7 @@ class FileBackendTest extends MediaWikiTestCase { $url = $this->backend->getFileHttpUrl( array( 'src' => $source ) ); if ( $url !== null ) { // supported - $data = Http::request( "GET", $url ); + $data = Http::request( "GET", $url, array(), __METHOD__ ); $this->assertEquals( $content, $data, "HTTP GET of URL has right contents ($backendName)." ); } -- 2.20.1