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;
// 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;
}
}