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;

  // 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 (!empty($this->requests[$this->scope])) {

    // 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[] = $e;
    }
  }
  $this->scope--;

  // Aggregate exceptions into an ExceptionCollection
  $exceptionCollection = null;
  if (!empty($this->exceptions)) {
    $exceptionCollection = new ExceptionCollection('Errors during multi transfer');
    while ($e = array_shift($this->exceptions)) {
      $exceptionCollection
        ->add($e);
    }
  }

  // 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 ($exceptionCollection) {
    throw $exceptionCollection;
  }
}