MediaWiki  1.23.2
MultiHttpClient Class Reference

Class to handle concurrent HTTP requests. More...

Collaboration diagram for MultiHttpClient:

Public Member Functions

 __construct (array $options)
 
 __destruct ()
 
 run (array $req, array $opts=array())
 Execute an HTTP(S) request. More...
 
 runMulti (array $reqs, array $opts=array())
 Execute a set of HTTP(S) requests concurrently. More...
 

Protected Member Functions

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

Protected Attributes

string null $caBundlePath
 SSL certificates path *. More...
 
integer $connTimeout = 10
 
integer $maxConnsPerHost = 50
 
resource $multiHandle = null
 
integer $reqTimeout = 300
 
bool $usePipelining = false
 

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 Request maps can use integer index 0 instead of 'method' and 1 instead of 'url'.
Author
Aaron Schulz
Since
1.23

Definition at line 42 of file MultiHttpClient.php.

Constructor & Destructor Documentation

◆ __construct()

MultiHttpClient::__construct ( array  $options)
Parameters
array$options
  • connTimeout : default connection timeout
  • reqTimeout : default request timeout
  • usePipelining : whether to use HTTP pipelining if possible (for all hosts)
  • maxConnsPerHost : maximum number of concurrent connections (per host)

Definition at line 57 of file MultiHttpClient.php.

References $options, array(), and as.

◆ __destruct()

MultiHttpClient::__destruct ( )

Definition at line 378 of file MultiHttpClient.php.

Member Function Documentation

◆ getCurlHandle()

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

Definition at line 242 of file MultiHttpClient.php.

References $matches, $name, $query, $value, array(), as, and list.

Referenced by runMulti().

◆ getCurlMulti()

MultiHttpClient::getCurlMulti ( )
protected
Returns
resource

Definition at line 366 of file MultiHttpClient.php.

References $multiHandle.

Referenced by runMulti().

◆ run()

MultiHttpClient::run ( array  $req,
array  $opts = array() 
)
final

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)
  • err : 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;
    Parameters
    array$reqHTTP request array
    array$opts
  • connTimeout : connection timeout per request
  • reqTimeout : post-connection timeout per request
    Returns
    array Response array for request

Definition at line 91 of file MultiHttpClient.php.

References array(), and runMulti().

◆ runMulti()

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

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)
  • err : 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; 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$reqMap of HTTP request arrays
array$opts
  • connTimeout : connection timeout per request
  • reqTimeout : post-connection timeout per request
  • 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

Definition at line 121 of file MultiHttpClient.php.

References $batch, $name, $value, array(), as, getCurlHandle(), and getCurlMulti().

Referenced by run().

Member Data Documentation

◆ $caBundlePath

string null MultiHttpClient::$caBundlePath
protected

SSL certificates path *.

Definition at line 44 of file MultiHttpClient.php.

◆ $connTimeout

integer MultiHttpClient::$connTimeout = 10
protected

Definition at line 45 of file MultiHttpClient.php.

◆ $maxConnsPerHost

integer MultiHttpClient::$maxConnsPerHost = 50
protected

Definition at line 48 of file MultiHttpClient.php.

◆ $multiHandle

resource MultiHttpClient::$multiHandle = null
protected

Definition at line 43 of file MultiHttpClient.php.

Referenced by getCurlMulti().

◆ $reqTimeout

integer MultiHttpClient::$reqTimeout = 300
protected

Definition at line 46 of file MultiHttpClient.php.

◆ $usePipelining

bool MultiHttpClient::$usePipelining = false
protected

Definition at line 47 of file MultiHttpClient.php.


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