static function retryDecider($retries, Request $request, Response $response = null, RequestException $exception = null)
{
// Limit the number of retries to 5
if ($retries >= 5) {
return false;
}
// Retry connection exceptions
if ($exception instanceof ConnectException) {
return true;
}
if ($response) {
// Retry on server errors
if ($response->getStatusCode() >= 500) {
return true;
}
// Retry on rate limits
if ($response->getStatusCode() == 429) {
$retryDelay = $response->getHeaderLine('Retry-After');
if (strlen($retryDelay)) {
printf(" retry delay: %d secs\n", (int) $retryDelay);
sleep((int) $retryDelay);
return true;
}
}
}
return false;
}