Sends a single request or an array of requests in parallel
array $requests Request(s) to send:
array Returns the response(s)
Overrides ClientInterface::send
public function send($requests) {
$curlMulti = $this
->getCurlMulti();
$multipleRequests = !$requests instanceof RequestInterface;
if (!$multipleRequests) {
$requests = array(
$requests,
);
}
foreach ($requests as $request) {
$curlMulti
->add($request);
}
try {
$curlMulti
->send();
} catch (ExceptionCollection $e) {
throw $multipleRequests ? $e : $e
->getIterator()
->offsetGet(0);
}
if (!$multipleRequests) {
return end($requests)
->getResponse();
}
else {
return array_map(function ($request) {
return $request
->getResponse();
}, $requests);
}
}