I want to manage multiple calls to an API. I am having an array of data and each element of array is used while calling an API and response is echoed back. The architecture goes following way:
<?php ini_set('max_execution_time', 300);//Did as loop takes >30s require_once 'other/VirusTotalApiV2.php'; $obj= new VirusTotalAPIV2("abc");//Forming object of API $handle=fopen("foo.txt","r"); // Obtaining the elements while($read=fgets($handle))//Each line stores an element { $counter=0; $report=$obj->getFileReport($read);//Calling API function //var_dump($report); echo "<table> <tr> <td>Antivirus</td> <td>Result</td> <td>Update</td> </tr>"; foreach($report->scans as $key=>$value){ echo "<tr>"; echo "<td>".$key."</td>"; echo "<td>".result($value->result)."</td>"; echo "<td>".$value->update."</td>"; echo "</tr>"; $counter++; } } echo $counter; fclose($handle); function result($input){ if($input==null) { return "No Issue"; } } Can I increase the efficiency of this calling as currently, the final output is receieved(at once) after 10s-15s and till that time page keeps loading. Please suggest some better way out.
curl_multisuggestion below doesn't do the trick, you might need to use threads: php.net/manual/en/intro.pthreads.php