/** * This function ensures that a response was set on a transaction. If one * was not set, then the request is retried if possible. This error * typically means you are sending a payload, curl encountered a * "Connection died, retrying a fresh connect" error, tried to rewind the * stream, and then encountered a "necessary data rewind wasn't possible" * error, causing the request to be sent through curl_multi_info_read() * without an error status. * * @param TransactionInterface $transaction * @param BatchContext $context * * @return bool Returns true if it's OK, and false if it failed. * @throws \GuzzleHttp\Exception\RequestException If it failed and cannot * recover. */ private function validateResponseWasSet(TransactionInterface $transaction, BatchContext $context) { if ($transaction->getResponse()) { return true; } $body = $transaction->getRequest()->getBody(); if (!$body) { // This is weird and should probably never happen. RequestEvents::emitError($transaction, new RequestException('No response was received for a request with no body. This' . ' could mean that you are saturating your network.', $transaction->getRequest())); } elseif (!$body->isSeekable() || !$body->seek(0)) { // Nothing we can do with this. Sorry! RequestEvents::emitError($transaction, new RequestException('The connection was unexpectedly closed. The request would' . ' have been retried, but attempting to rewind the' . ' request body failed. Consider wrapping your request' . ' body in a CachingStream decorator to work around this' . ' issue if necessary.', $transaction->getRequest())); } else { $this->retryFailedConnection($transaction, $context); } return false; }
private function handleError(TransactionInterface $transaction, $info, $handle) { $error = curl_error($handle); $this->releaseEasyHandle($handle); RequestEvents::emitError($transaction, new AdapterException("cURL error {$info['curl_result']}: {$error}"), $info); }
private function isCurlException(TransactionInterface $transaction, array $curl, BatchContext $context, array $info) { if (CURLM_OK == $curl['result'] || CURLM_CALL_MULTI_PERFORM == $curl['result']) { return false; } $request = $transaction->getRequest(); try { // Send curl stats along if they are available $stats = ['curl_result' => $curl['result']] + $info; RequestEvents::emitError($transaction, new RequestException(sprintf('[curl] (#%s) %s [url] %s', $curl['result'], function_exists('curl_strerror') ? curl_strerror($curl['result']) : self::ERROR_STR, $request->getUrl()), $request), $stats); } catch (RequestException $e) { $this->throwException($e, $context); } return true; }