Rate Limit and Exponential Decay

We implement rate limit protection in our API. To protect your App or a user from being blocked we strongly suggest that you implement an exponential decay in the event of any request failures.

Below is an example of such a decay in PHP:

$response = false;
$delay = 0.5; // seconds
$maxDelay = 2; // seconds
while(true) {
$response = curl_exec($curl);
// var_dump(curl_getinfo($curl)); // use for debugging
if ($response !== false) {
curl_close($curl);
break;
} else {
$seconds = intval($delay);
$nanoseconds = ($delay - $seconds) * 1e9;
time_nanosleep($seconds, $nanoseconds);
$delay *= 2;
if ($delay = $maxDelay) {
$error = curl_error($curl);
$errno = curl_errno($curl);
fail('Error: ' . $error . ', Errno: ' . $errno);
curl_close($curl);
return false;
}
}
}

No luck what you're looking for?

Let us know details about your question. We'll get back to you!