Client/RestClient.php
private static function createBackoff(array $options, LoggerInterface $logger)
    {
        $headerName = isset($options['http']['retryHeader']) ? $options['http']['retryHeader'] : 'Retry-After';
        $httpRetryCodes = isset($options['http']['codes']) ? $options['http']['codes'] : [500, 502, 503, 504, 408, 420, 429];
        $maxRetries = isset($options['maxRetries']) ? (int) $options['maxRetries']: 10;

        $curlRetryCodes = isset($options['curl']['codes']) ? $options['curl']['codes'] : [
            CURLE_OPERATION_TIMEOUTED,
            CURLE_COULDNT_RESOLVE_HOST,
            CURLE_COULDNT_CONNECT,
            CURLE_SSL_CONNECT_ERROR,
            CURLE_GOT_NOTHING,
            CURLE_RECV_ERROR
        ];

        return new RetrySubscriber([
            'filter' => RetrySubscriber::createChainFilter([
                RetrySubscriber::createStatusFilter($httpRetryCodes),
                RetrySubscriber::createCurlFilter($curlRetryCodes)
            ]),
            'max' => $maxRetries,
            'delay' => function ($retries, AbstractTransferEvent $event) use ($headerName, $logger) {
                $delay = self::getRetryDelay($retries, $event, $headerName);

                $errData = [
                    "http_code" => !empty($event->getTransferInfo()['http_code']) ? $event->getTransferInfo()['http_code'] : null,
                    "body" => is_null($event->getResponse()) ? null : (string) $event->getResponse()->getBody(),
                    "url" =>  !empty($event->getTransferInfo()['url']) ? $event->getTransferInfo()['url'] : $event->getRequest()->getUrl(),
                ];
                if ($event instanceof ErrorEvent) {
                    $errData["message"] = $event->getException()->getMessage();
                }
                $logger->debug("Http request failed, retrying in {$delay}s", $errData);

                // ms > s
                return 1000 * $delay;
            }
        ]);
    }
private static function createBackoff(array $options, LoggerInterface $logger)
    {
        $headerName = isset($options['http']['retryHeader']) ? $options['http']['retryHeader'] : 'Retry-After';
        $httpRetryCodes = isset($options['http']['codes']) ? $options['http']['codes'] : [500, 502, 503, 504, 408, 420, 429];
        $maxRetries = isset($options['maxRetries']) ? (int) $options['maxRetries']: 10;

        $curlRetryCodes = isset($options['curl']['codes']) ? $options['curl']['codes'] : [
            CURLE_OPERATION_TIMEOUTED,
            CURLE_COULDNT_RESOLVE_HOST,
            CURLE_COULDNT_CONNECT,
            CURLE_SSL_CONNECT_ERROR,
            CURLE_GOT_NOTHING,
            CURLE_RECV_ERROR
        ];

        return new RetrySubscriber([
            'filter' => RetrySubscriber::createChainFilter([
                RetrySubscriber::createStatusFilter($httpRetryCodes),
                RetrySubscriber::createCurlFilter($curlRetryCodes)
            ]),
            'max' => $maxRetries,
            'delay' => function ($retries, AbstractTransferEvent $event) use ($headerName, $logger) {
                $delay = self::getRetryDelay($retries, $event, $headerName);

                $errData = [
                    "http_code" => !empty($event->getTransferInfo()['http_code']) ? $event->getTransferInfo()['http_code'] : null,
                    "body" => is_null($event->getResponse()) ? null : (string) $event->getResponse()->getBody(),
                    "url" =>  !empty($event->getTransferInfo()['url']) ? $event->getTransferInfo()['url'] : $event->getRequest()->getUrl(),
                ];
                if ($event instanceof ErrorEvent) {
                    $errData["message"] = $event->getException()->getMessage();
                }
                $logger->debug("Http request failed, retrying in {$delay}s", $errData);

                // ms > s
                return 1000 * $delay;
            }
        ]);
    }
private static function createBackoff ( array $ options , LoggerInterface $ logger ) { $ headerName = isset ( $ options [ 'http' ] [ 'retryHeader' ] ) ? $ options [ 'http' ] [ 'retryHeader' ] : 'Retry-After' ; $ httpRetryCodes = isset ( $ options [ 'http' ] [ 'codes' ] ) ? $ options [ 'http' ] [ 'codes' ] : [ 500 , 502 , 503 , 504 , 408 , 420 , 429 ] ; $ maxRetries = isset ( $ options [ 'maxRetries' ] ) ? ( int ) $ options [ 'maxRetries' ] : 10 ; $ curlRetryCodes = isset ( $ options [ 'curl' ] [ 'codes' ] ) ? $ options [ 'curl' ] [ 'codes' ] : [ CURLE_OPERATION_TIMEOUTED , CURLE_COULDNT_RESOLVE_HOST , CURLE_COULDNT_CONNECT , CURLE_SSL_CONNECT_ERROR , CURLE_GOT_NOTHING , CURLE_RECV_ERROR ] ; return new RetrySubscriber ( [ 'filter' => RetrySubscriber :: createChainFilter ( [ RetrySubscriber :: createStatusFilter ( $ httpRetryCodes ) , RetrySubscriber :: createCurlFilter ( $ curlRetryCodes ) ] ) , 'max' => $ maxRetries , 'delay' => function ( $ retries , AbstractTransferEvent $ event ) use ( $ headerName , $ logger ) { $ delay = self :: getRetryDelay ( $ retries , $ event , $ headerName ) ; $ errData = [ "http_code" => ! empty ( $ event -> getTransferInfo ( ) [ 'http_code' ] ) ? $ event -> getTransferInfo ( ) [ 'http_code' ] : null , "body" => is_null ( $ event -> getResponse ( ) ) ? null : ( string ) $ event -> getResponse ( ) -> getBody ( ) , "url" => ! empty ( $ event -> getTransferInfo ( ) [ 'url' ] ) ? $ event -> getTransferInfo ( ) [ 'url' ] : $ event -> getRequest ( ) -> getUrl ( ) , ] ; if ( $ event instanceof ErrorEvent ) { $ errData [ "message" ] = $ event -> getException ( ) -> getMessage ( ) ; } $ logger -> debug ( "Http request failed, retrying in {$delay}s" , $ errData ) ; // ms > s return 1000 * $ delay ; } ] ) ; }
Create exponential backoff for GuzzleClient

options
- maxRetries: (integer) max retries count
- http
- retryHeader (string) header containing retry time header
- codes (array) list of status codes to retry on
- curl
- codes (array) list of error codes to retry on

@param array $options
@param LoggerInterface $logger
@return RetrySubscriber
Create exponential backoff for GuzzleClient