I have an array with 12500 elements (company IDs). I need run 1 PHP file for all the elements in the array.
Please let me know what is the best way to do that.
I want to use Curl inside the for each loop to execute the file:
<?php
$array = ['123','124','125','126','127',......,'12503'];
foreach ($array as &$value) {
$url = 'https://*****/*****/List_daily.php?accountid='.$value.'';
$resp = call_curl($url);
echo $resp."<br>"
/**
Here is where I want to execute the file
**/
}
function call_curl($url){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => '5'
));
$resp = curl_exec($curl);
curl_close($curl);
return $resp;
}
?>
You can try parallel curl requests for the array you have to have better performance, you can use this as an example PHP Parallel curl requests
if you don't send any special data to CURL, you can do same easy way with file_get_contents();
if(count($array)) {
$url='https://*****/*****/List_daily.php?accountid=';
foreach ($array as $v) {
$resp = file_get_contents($url.$v);
if($resp) {
echo $resp."<br/>
"; //or do something
} else {
//error getting data
}
}
}