Send a pool of {
ExceptionCollection if any requests threw exceptions during the transfer.
Overrides CurlMultiInterface::send
RequestInterface} requests.
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;
}
}