MediaWiki REL1_31
MultiHttpClient Class Reference

Class to handle concurrent HTTP requests. More...

Inheritance diagram for MultiHttpClient:
Collaboration diagram for MultiHttpClient:

Public Member Functions

 __construct (array $options)
 
 __destruct ()
 
 run (array $req, array $opts=[])
 Execute an HTTP(S) request.
 
 runMulti (array $reqs, array $opts=[])
 Execute a set of HTTP(S) requests concurrently.
 
 setLogger (LoggerInterface $logger)
 Register a logger.
 

Protected Member Functions

 getCurlHandle (array &$req, array $opts=[])
 
 getCurlMulti ()
 

Protected Attributes

string null $caBundlePath
 SSL certificates path.
 
int $connTimeout = 10
 
LoggerInterface $logger
 
int $maxConnsPerHost = 50
 
resource $multiHandle = null
 
string null $proxy
 proxy
 
int $reqTimeout = 300
 
bool $usePipelining = false
 
string $userAgent = 'wikimedia/multi-http-client v1.0'
 

Detailed Description

Class to handle concurrent HTTP requests.

HTTP request maps are arrays that use the following format:

  • method : GET/HEAD/PUT/POST/DELETE
  • url : HTTP/HTTPS URL
  • query : <query parameter field/value associative array> (uses RFC 3986)
  • headers : <header name/value associative array>
  • body : source to get the HTTP request body from; this can simply be a string (always), a resource for PUT requests, and a field/value array for POST request; array bodies are encoded as multipart/form-data and strings use application/x-www-form-urlencoded (headers sent automatically)
  • stream : resource to stream the HTTP response body to
  • proxy : HTTP proxy to use
  • flags : map of boolean flags which supports:
    • relayResponseHeaders : write out header via header() Request maps can use integer index 0 instead of 'method' and 1 instead of 'url'.
Since
1.23

Definition at line 48 of file MultiHttpClient.php.

Constructor & Destructor Documentation

◆ __construct()

MultiHttpClient::__construct ( array $options)
Parameters
array$options
  • connTimeout : default connection timeout (seconds)
  • reqTimeout : default request timeout (seconds)
  • proxy : HTTP proxy to use
  • usePipelining : whether to use HTTP pipelining if possible (for all hosts)
  • maxConnsPerHost : maximum number of concurrent connections (per host)
  • userAgent : The User-Agent header value to send
Exceptions
Exception

Definition at line 78 of file MultiHttpClient.php.

References $options.

◆ __destruct()

MultiHttpClient::__destruct ( )

Definition at line 440 of file MultiHttpClient.php.

Member Function Documentation

◆ getCurlHandle()

MultiHttpClient::getCurlHandle ( array & $req,
array $opts = [] )
protected
Parameters
array&$reqHTTP request map
array$opts
  • connTimeout : default connection timeout
  • reqTimeout : default request timeout
Returns
resource
Exceptions
Exception

Definition at line 285 of file MultiHttpClient.php.

References $connTimeout, $header, $matches, $proxy, $query, $req, $reqTimeout, $userAgent, $value, and list.

Referenced by runMulti().

◆ getCurlMulti()

MultiHttpClient::getCurlMulti ( )
protected
Returns
resource
Exceptions
Exception

Definition at line 417 of file MultiHttpClient.php.

References $multiHandle.

Referenced by runMulti().

◆ run()

MultiHttpClient::run ( array $req,
array $opts = [] )

Execute an HTTP(S) request.

This method returns a response map of:

  • code : HTTP response code or 0 if there was a serious cURL error
  • reason : HTTP response reason (empty if there was a serious cURL error)
  • headers : <header name/value associative array>
  • body : HTTP response body or resource (if "stream" was set)
  • error : Any cURL error string The map also stores integer-indexed copies of these values. This lets callers do:
    list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $http->run( $req );
    deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
    Definition deferred.txt:11
    this hook is for auditing only $req
    Definition hooks.txt:990
    Parameters
    array$reqHTTP request array
    array$opts
  • connTimeout : connection timeout per request (seconds)
  • reqTimeout : post-connection timeout per request (seconds)
    Returns
    array Response array for request

Definition at line 118 of file MultiHttpClient.php.

References runMulti().

◆ runMulti()

MultiHttpClient::runMulti ( array $reqs,
array $opts = [] )

Execute a set of HTTP(S) requests concurrently.

The maps are returned by this method with the 'response' field set to a map of:

  • code : HTTP response code or 0 if there was a serious cURL error
  • reason : HTTP response reason (empty if there was a serious cURL error)
  • headers : <header name/value associative array>
  • body : HTTP response body or resource (if "stream" was set)
  • error : Any cURL error string The map also stores integer-indexed copies of these values. This lets callers do:
    list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $req['response'];
    All headers in the 'headers' field are normalized to use lower case names. This is true for the request headers and the response headers. Integer-indexed method/URL entries will also be changed to use the corresponding string keys.
Parameters
array$reqsMap of HTTP request arrays
array$opts
  • connTimeout : connection timeout per request (seconds)
  • reqTimeout : post-connection timeout per request (seconds)
  • usePipelining : whether to use HTTP pipelining if possible
  • maxConnsPerHost : maximum number of concurrent connections (per host)
Returns
array $reqs With response array populated for each
Exceptions
Exception

Definition at line 148 of file MultiHttpClient.php.

References $batch, $req, $value, getCurlHandle(), and getCurlMulti().

Referenced by run().

◆ setLogger()

MultiHttpClient::setLogger ( LoggerInterface $logger)

Register a logger.

Parameters
LoggerInterface$logger

Definition at line 436 of file MultiHttpClient.php.

References $logger.

Member Data Documentation

◆ $caBundlePath

string null MultiHttpClient::$caBundlePath
protected

SSL certificates path.

Definition at line 52 of file MultiHttpClient.php.

◆ $connTimeout

int MultiHttpClient::$connTimeout = 10
protected

Definition at line 54 of file MultiHttpClient.php.

Referenced by getCurlHandle().

◆ $logger

LoggerInterface MultiHttpClient::$logger
protected

Definition at line 66 of file MultiHttpClient.php.

Referenced by setLogger().

◆ $maxConnsPerHost

int MultiHttpClient::$maxConnsPerHost = 50
protected

Definition at line 60 of file MultiHttpClient.php.

◆ $multiHandle

resource MultiHttpClient::$multiHandle = null
protected

Definition at line 50 of file MultiHttpClient.php.

Referenced by getCurlMulti().

◆ $proxy

string null MultiHttpClient::$proxy
protected

proxy

Definition at line 62 of file MultiHttpClient.php.

Referenced by getCurlHandle().

◆ $reqTimeout

int MultiHttpClient::$reqTimeout = 300
protected

Definition at line 56 of file MultiHttpClient.php.

Referenced by getCurlHandle().

◆ $usePipelining

bool MultiHttpClient::$usePipelining = false
protected

Definition at line 58 of file MultiHttpClient.php.

◆ $userAgent

string MultiHttpClient::$userAgent = 'wikimedia/multi-http-client v1.0'
protected

Definition at line 64 of file MultiHttpClient.php.

Referenced by getCurlHandle().


The documentation for this class was generated from the following file: