public function CurlMulti::add

Adds a request to a batch of requests to be sent in parallel.

Async requests adds a request to the current scope to be executed in parallel with any currently executing cURL handles. You may only add an async request while other requests are transferring. Attempting to add an async request while no requests are transferring will add the request normally in the next available scope (e.g. 0).

Parameters

RequestInterface $request Request to add:

bool $async Set to TRUE to add to the current scope:

Return value

self

Overrides CurlMultiInterface::add

File

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

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 add(RequestInterface $request, $async = false) {
  if ($async && $this->state != self::STATE_SENDING) {
    $async = false;
  }
  $this->requestCache = null;
  $scope = $async ? $this->scope : $this->scope + 1;
  if (!isset($this->requests[$scope])) {
    $this->requests[$scope] = array(
      $request,
    );
  }
  else {
    $this->requests[$scope][] = $request;
  }
  $this
    ->dispatch(self::ADD_REQUEST, array(
    'request' => $request,
  ));

  // If requests are currently transferring and this is async, then the
  // request must be prepared now as the send() method is not called.
  if ($async && $this->state == self::STATE_SENDING) {
    $this
      ->beforeSend($request);
  }
  return $this;
}