public function Client::send

Sends a single request or an array of requests in parallel

Parameters

array $requests Request(s) to send:

Return value

array Returns the response(s)

Overrides ClientInterface::send

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Client.php, line 350

Class

Client
HTTP client

Namespace

Guzzle\Http

Code

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);
  }
}