0

I have a .php file with following codes. I wanted to make the curl request in parallel because in below code - every request is taking minimum 1 second. I wanted to process at least 10 requests within this time. How can I achieve this?

<?php
$data = file("test.txt", FILE_IGNORE_NEW_LINES);
$count = count($data);
for( $i = 0; $i<$count; $i++)
{
    $mob=$data[$i];
    $url = "http://127.0.0.1/test.php?category=243&to=$mob";
    echo $url."\n";

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $htmlText = curl_exec($ch);
    curl_close($ch);
}
?>

test.txt file have some data like below:

100100
200200
300300
......
......

Any help would be highly appreciated.

Rezuan
  • 95
  • 11
  • 5
    Possible duplicate of [PHP Parallel curl requests](https://stackoverflow.com/questions/9308779/php-parallel-curl-requests) – Devon Bessemer Jun 19 '18 at 13:11

1 Answers1

0

You probably want to use: curl_multi_add_handle

Although you could also use exec, but this would be more difficult

ET Come Back
  • 198
  • 6