Good morning people Stack overflow !!
Next, I'm doing an integration next to my Sql server
bank of a Rest API, where I pass the information I want in the URL and get the content as json
I make several requests in this API, because I make a SELECT
in my bank that returns all the ID's of the sales opportunities and I pass this ID in the API url, only that from time to time some errors occur because the API allows only 100 requests every 10 seconds, I put a counter to make a sleep
, but still the error continues, follow the code below:
while($RFP = odbc_fetch_array($result)) {
//contador que coloquei para o limite da requisição da api
if($contador >= 96){
$contador = 0;
sleep(10); // 5 segundos para proxima requisitar da API
}
$url = "https://api.pipedrive.com/v1/deals/".$RFP['ID']."/flow?start=0&api_token=meutokenaqui";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cAlljson = curl_exec($ch);
// liberar
curl_close($ch);
$contador = $contador + 1; // Contador para limite de requisições da API
// Decodifica o Json em Objeto
$cAlljson = json_decode($cAlljson);
$cAlljson = $cAlljson->data;
if (is_array($cAlljson)){
foreach($cAlljson as $e)
{