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?

Recommended Answers

All 2 Replies

I have solved it using sleep

this is the code if anyone needs it


$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 />";
    echo time() . "<br />";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.