Hi guys I am making a tool which will fetch telephone numbers from the database and make a curl/api request to validate the number and get it's info then update certain fields in the database based from the API response.
So I have a table called phones
which has
->id
->number
->network
->country
So in my table only the id
and number
which has values, network
and country
is null. Which is the reason I will use API that will update those fields depending on the number. However there's a problem, so basically what will happen is I will loop on all those numbers like so:
$phone = Phone::all();
foreach ($phone as $key => $value)
{
// Call the API that will get the details in the current number
// and update the details in the table for the current number
/** Some code for API Call **/
//Update Script
$update = Phone::find($value->id);
$update->network = $network;
$update->country = $country;
$update->country_prefix = $country_prefix;
$update->status = $status;
$update->remarks = $remarks;
$update->save();
}
That will work fine and do my task, but problem is this is very slow when I looped in let's say, 50,000 records, coz before it can send the next curl request, it must wait for the response of the previous one right? Question is how can I make it a 20 request per loop count? Coz the API I'm using supports 20 request per second so I wan't to maximize it.
I know my loop will change coz I need to get 20 records at a time and not repeating the same records again.