1: <?php
2:
3: namespace Guzzle\Plugin\Backoff;
4:
5: use Guzzle\Http\Message\RequestInterface;
6: use Guzzle\Http\Message\Response;
7: use Guzzle\Http\Exception\HttpException;
8:
9: /**
10: * Strategy used to retry HTTP requests based on the response code.
11: *
12: * Retries 500 and 503 error by default.
13: */
14: class HttpBackoffStrategy extends AbstractErrorCodeBackoffStrategy
15: {
16: /**
17: * @var array Default cURL errors to retry
18: */
19: protected static $defaultErrorCodes = array(500, 503);
20:
21: /**
22: * {@inheritdoc}
23: */
24: protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
25: {
26: if ($response) {
27: //Short circuit the rest of the checks if it was successful
28: if ($response->isSuccessful()) {
29: return false;
30: } else {
31: return isset($this->errorCodes[$response->getStatusCode()]) ? true : null;
32: }
33: }
34: }
35: }
36: