$defaultErrorCodes
$defaultErrorCodes : array
Strategy used to retry when certain cURL error codes are encountered.
$next : \Guzzle\Plugin\Backoff\AbstractBackoffStrategy
__construct(array $codes = null, \Guzzle\Plugin\Backoff\BackoffStrategyInterface $next = null)
array | $codes | Array of codes that should be retried |
\Guzzle\Plugin\Backoff\BackoffStrategyInterface | $next | The optional next strategy |
setNext(\Guzzle\Plugin\Backoff\AbstractBackoffStrategy $next)
\Guzzle\Plugin\Backoff\AbstractBackoffStrategy | $next | Next strategy in the chain |
getNext() : \Guzzle\Plugin\Backoff\AbstractBackoffStrategy|null
Get the next backoff strategy in the chain
getBackoffPeriod(integer $retries, \Guzzle\Http\Message\RequestInterface $request, \Guzzle\Http\Message\Response $response = null, \Guzzle\Http\Exception\HttpException $e = null) : boolean|integer
Get the amount of time to delay in seconds before retrying a request
integer | $retries | Number of retries of the request |
\Guzzle\Http\Message\RequestInterface | $request | Request that was sent |
\Guzzle\Http\Message\Response | $response | Response that was received. Note that there may not be a response |
\Guzzle\Http\Exception\HttpException | $e | Exception that was encountered if any |
Returns false to not retry or the number of seconds to delay between retries
getDelay( $retries, \Guzzle\Http\Message\RequestInterface $request, \Guzzle\Http\Message\Response $response = null, \Guzzle\Http\Exception\HttpException $e = null)
$retries | ||
\Guzzle\Http\Message\RequestInterface | $request | |
\Guzzle\Http\Message\Response | $response | |
\Guzzle\Http\Exception\HttpException | $e |
<?php
namespace Guzzle\Plugin\Backoff;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;
use Guzzle\Http\Exception\CurlException;
/**
* Strategy used to retry when certain cURL error codes are encountered.
*/
class CurlBackoffStrategy extends AbstractErrorCodeBackoffStrategy
{
/** @var array Default cURL errors to retry */
protected static $defaultErrorCodes = array(
CURLE_COULDNT_RESOLVE_HOST, CURLE_COULDNT_CONNECT, CURLE_PARTIAL_FILE, CURLE_WRITE_ERROR, CURLE_READ_ERROR,
CURLE_OPERATION_TIMEOUTED, CURLE_SSL_CONNECT_ERROR, CURLE_HTTP_PORT_FAILED, CURLE_GOT_NOTHING,
CURLE_SEND_ERROR, CURLE_RECV_ERROR
);
protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
{
if ($e && $e instanceof CurlException) {
return isset($this->errorCodes[$e->getErrorNo()]) ? true : null;
}
}
}