0

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;
    }
?>
Bas Peeters
  • 3,269
  • 4
  • 33
  • 49

2 Answers2

0

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

Bilel BM
  • 21
  • 4
0

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/>\n"; //or do something
        } else {
            //error getting data
        }
    }
}
Aleksey
  • 21
  • 2