示例#1
0
 /**
  * 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.
  */
 private static function retryFailedRewind(callable $handler, array $request, array $response)
 {
     // If there is no body, then there is some other kind of issue. This
     // is weird and should probably never happen.
     if (!isset($request['body'])) {
         $response['err_message'] = 'No response was received for a request ' . 'with no body. This could mean that you are saturating your ' . 'network.';
         return self::createErrorResponse($handler, $request, $response);
     }
     if (!Core::rewindBody($request)) {
         $response['err_message'] = 'The connection unexpectedly failed ' . 'without providing an error. The request would have been ' . 'retried, but attempting to rewind the request body failed.';
         return self::createErrorResponse($handler, $request, $response);
     }
     // Retry no more than 3 times before giving up.
     if (!isset($request['curl']['retries'])) {
         $request['curl']['retries'] = 1;
     } elseif ($request['curl']['retries'] == 2) {
         $response['err_message'] = 'The cURL request was retried 3 times ' . 'and did no succeed. cURL was unable to rewind the body of ' . 'the request and subsequent retries resulted in the same ' . 'error. Turn on the debug option to see what went wrong. ' . 'See https://bugs.php.net/bug.php?id=47204 for more information.';
         return self::createErrorResponse($handler, $request, $response);
     } else {
         $request['curl']['retries']++;
     }
     return $handler($request);
 }
示例#2
0
 public function testRewindsToStrings()
 {
     $this->assertTrue(Core::rewindBody(['body' => new StrClass()]));
 }