0

Basically I am woking on this project where I have been given an api.

the maximum number of times i can access is 20 calls per second

I need to call this api say 500 times

I can do simple loop which is

foreach($test as $call){

//call api using $call variable value

}

How do I makesure that I am only execuiting it no more than 20 times per second?

2
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by t_thakar
0

I have solved it using sleep

this is the code if anyone needs it

<?php

$raw = "124,4235,235,235,235,457,679,980,2435,123,567,78,45,3,1,7,9,34,2,45,86,765,46,32,6,83,63,25,23,35,65,68,79,80,457,32,53,214,14,465,568,34,64,235,523,234,47,96";
$numbers = explode(",", $raw);
$chunks = array_chunk($numbers, 20);
echo time() . "<br />";
foreach($chunks as $chunk){

    foreach($chunk as $num){
        echo $num . "<br />";
    }
    sleep(1);
    echo time() . "<br />";

}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.