public function CurlMulti::send

Send a pool of {

Throws

ExceptionCollection if any requests threw exceptions during the transfer.

Overrides CurlMultiInterface::send

See also

RequestInterface} requests.

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Curl/CurlMulti.php, line 256

Class

CurlMulti
Send { This implementation allows callers to send blocking requests that return back to the caller when their requests complete, regardless of whether or not previously sending requests in the curl_multi object have completed. The implementation…

Namespace

Guzzle\Http\Curl

Code

public function send() {
  $this->scope++;
  $this->state = self::STATE_SENDING;
  $requestsInScope = empty($this->requests[$this->scope]) ? array() : $this->requests[$this->scope];

  // Only prepare and send requests that are in the current recursion scope
  // Only enter the main perform() loop if there are requests in scope
  if ($requestsInScope) {

    // Any exceptions thrown from this event should break the entire flow of sending requests
    $this
      ->dispatch(self::BEFORE_SEND, array(
      'requests' => $this->requests[$this->scope],
    ));
    foreach ($this->requests[$this->scope] as $request) {
      if ($request
        ->getState() != RequestInterface::STATE_TRANSFER) {
        $this
          ->beforeSend($request);
      }
    }
    try {
      $this
        ->perform();
    } catch (\Exception $e) {
      $this->exceptions[] = array(
        'request' => null,
        'exception' => $e,
      );
    }
  }
  $this->scope--;

  // Aggregate exceptions into a MultiTransferException if needed
  $multiException = $this
    ->buildMultiTransferException($requestsInScope);

  // Complete the transfer if this is not a nested scope
  if ($this->scope == -1) {
    $this->state = self::STATE_COMPLETE;
    $this
      ->dispatch(self::COMPLETE);
    $this
      ->reset();
  }

  // Throw any exceptions that were encountered
  if ($multiException) {
    throw $multiException;
  }
}