send_multi_request ( $handles, $opt )

Sends the request using curl_multi_exec(), enabling parallel requests. Uses the “rolling” method.

Access

public

Parameters

Parameter

Type

Required

Description

$handles

array

Required

An indexed array of cURL handles to process simultaneously.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • callback - string|array - Optional - The string name of a function to pass the response data to. If this is a method, pass an array where the [0] index is the class and the [1] index is the method name.
  • limit - integer - Optional - The number of simultaneous requests to make. This can be useful for scaling around slow server responses. Defaults to trusting cURLs judgement as to how many to use.

Returns

Type

Description

array

Post-processed cURL responses.

Examples

Collect cURL handles for two requests, fire them, and then display the response bodies.

$http = new RequestCore();

$responses = $http->send_multi_request(array(
	$http->set_request_url('http://github.com/skyzyx/requestcore/raw/master/_tests/test_request.txt')->prep_request(),
	$http->set_request_url('http://github.com/skyzyx/requestcore/raw/master/_tests/test_request2.txt')->prep_request()
));

$bodies = array(
	$responses[0]->body,
	$responses[1]->body,
);

var_dump($bodies);
Result:
array(2) {
  [0]=>
  string(48) "abcdefghijklmnopqrstuvwxyz
0123456789
!@#$%^&*()"
  [1]=>
  string(48) ")(*&^%$#@!
9876543210
zyxwvutsrqponmljkihgfedcba"
}

Source

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback