Added profiling to MWHttpRequest and Http.
authorTyler Anthony Romeo <tylerromeo@gmail.com>
Mon, 18 Mar 2013 21:32:43 +0000 (17:32 -0400)
committerTyler Anthony Romeo <tylerromeo@gmail.com>
Mon, 18 Mar 2013 21:50:33 +0000 (17:50 -0400)
Added profile calls to various functions in
MWHttpRequest as well as to the wrapper
function Http::request.

Change-Id: I7f2819a075891dbc565a7524d56e7bf077ab089a

includes/HttpFunctions.php

index dc65c67..98d36d3 100644 (file)
@@ -58,6 +58,8 @@ class Http {
         */
        public static function request( $method, $url, $options = array() ) {
                wfDebug( "HTTP: $method: $url\n" );
+               wfProfileIn( __METHOD__ . "-$method" );
+
                $options['method'] = strtoupper( $method );
 
                if ( !isset( $options['timeout'] ) ) {
@@ -68,8 +70,11 @@ class Http {
                $status = $req->execute();
 
                if ( $status->isOK() ) {
-                       return $req->getContent();
+                       $content = $req->getContent();
+                       wfProfileOut( __METHOD__ . "-$method" );
+                       return $content;
                } else {
+                       wfProfileOut( __METHOD__ . "-$method" );
                        return false;
                }
        }
@@ -427,6 +432,8 @@ class MWHttpRequest {
        public function execute() {
                global $wgTitle;
 
+               wfProfileIn( __METHOD__ );
+
                $this->content = "";
 
                if ( strtoupper( $this->method ) == "HEAD" ) {
@@ -446,6 +453,8 @@ class MWHttpRequest {
                if ( !isset( $this->reqHeaders['User-Agent'] ) ) {
                        $this->setUserAgent( Http::userAgent() );
                }
+
+               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -454,6 +463,8 @@ class MWHttpRequest {
         * found in an array in the member variable headerList.
         */
        protected function parseHeader() {
+               wfProfileIn( __METHOD__ );
+
                $lastname = "";
 
                foreach ( $this->headerList as $header ) {
@@ -470,6 +481,8 @@ class MWHttpRequest {
                }
 
                $this->parseCookies();
+
+               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -603,6 +616,8 @@ class MWHttpRequest {
         * Parse the cookies in the response headers and store them in the cookie jar.
         */
        protected function parseCookies() {
+               wfProfileIn( __METHOD__ );
+
                if ( !$this->cookieJar ) {
                        $this->cookieJar = new CookieJar;
                }
@@ -613,6 +628,8 @@ class MWHttpRequest {
                                $this->cookieJar->parseCookieResponseHeader( $cookie, $url['host'] );
                        }
                }
+
+               wfProfileIn( __METHOD__ );
        }
 
        /**
@@ -700,9 +717,12 @@ class CurlHttpRequest extends MWHttpRequest {
        }
 
        public function execute() {
+               wfProfileIn( __METHOD__ );
+
                parent::execute();
 
                if ( !$this->status->isOK() ) {
+                       wfProfileOut( __METHOD__ );
                        return $this->status;
                }
 
@@ -746,6 +766,7 @@ class CurlHttpRequest extends MWHttpRequest {
                $curlHandle = curl_init( $this->url );
 
                if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
+                       wfProfileOut( __METHOD__ );
                        throw new MWException( "Error setting curl options." );
                }
 
@@ -777,6 +798,8 @@ class CurlHttpRequest extends MWHttpRequest {
                $this->parseHeader();
                $this->setStatus();
 
+               wfProfileOut( __METHOD__ );
+
                return $this->status;
        }
 
@@ -811,6 +834,8 @@ class PhpHttpRequest extends MWHttpRequest {
        }
 
        public function execute() {
+               wfProfileIn( __METHOD__ );
+
                parent::execute();
 
                if ( is_array( $this->postData ) ) {
@@ -903,11 +928,13 @@ class PhpHttpRequest extends MWHttpRequest {
 
                if ( $fh === false ) {
                        $this->status->fatal( 'http-request-error' );
+                       wfProfileOut( __METHOD__ );
                        return $this->status;
                }
 
                if ( $result['timed_out'] ) {
                        $this->status->fatal( 'http-timed-out', $this->url );
+                       wfProfileOut( __METHOD__ );
                        return $this->status;
                }
 
@@ -930,6 +957,8 @@ class PhpHttpRequest extends MWHttpRequest {
                }
                fclose( $fh );
 
+               wfProfileOut( __METHOD__ );
+
                return $this->status;
        }
 }