google/google-api-php-client — pull request #416 by whatthejeff (2014-12-01 18:13:41+00:00)
Title: Add support for retrying failed requests with exponential backoff.

This feature can be enabled by setting the `max_retries` configuration for the
`Google_Task_Runner` class:

~~~php
$client = new Google_Client();
$client->setClassConfig('Google_Task_Runner', 'max_retries', 5);
~~~

Once `max_retries` is configured, the following error types will be retried by
default:

* Errors with a `500` or a `503` HTTP status code.
* Errors with a `rateLimitExceeded` or a `userRateLimitExceeded` reason type.
* cURL errors:
* `CURLE_COULDNT_RESOLVE_HOST`
* `CURLE_COULDNT_CONNECT`
* `CURLE_OPERATION_TIMEOUTED`
* `CURLE_SSL_CONNECT_ERROR`
* `CURLE_GOT_NOTHING`

These error types can be configured using the `retry_map` configurations for
the `Google_IO_Exception` and `Google_Service_Exception` classes. The retry map
is an associative array which maps errors types to the number of times each
error can be retried (-1 can be used to retry an error indefinitely). For
example:

~~~php
$client = new Google_Client();
$client->setClassConfig(
'Google_Service_Exception',
'retry_map',
array(
// Don't retry 500 errors
'500' => 0,
// Retry 503 errors once
'503' => 1,
// Retry rate limit errors until we hit `max_retries`
'rateLimitExceeded' => -1,
'userRateLimitExceeded' => -1
)
);
~~~

For convenience, `Google_Config` provides three constants for configuring retry
limits: `Google_Config::TASK_RETRY_NEVER`, `Google_Config::TASK_RETRY_ONCE`, and
`Google_Config::TASK_RETRY_ALWAYS`.