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).
RequestInterface $request Request to add:
bool $async Set to TRUE to add to the current scope:
self
Overrides CurlMultiInterface::add
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;
}