Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parallel downloads in PHP

I want to download (or simply file_get_contents) for 5 places. I wait say 1.2 sec for each that means in total 1.2X5=6 seconds. I want to save waiting time. I thought I could wait 1.3 sec is enough. How can I approach?

like image 951
nerkn Avatar asked Oct 28 '10 18:10

nerkn


2 Answers

You can use the curl_multi_* functions to achieve parallel downloads.

like image 100
codaddict Avatar answered Nov 15 '22 22:11

codaddict


this is possible but only by creating multiple threads outside PHP

With PHP scripts run in a single thread, meaning that it can only do 1 task at a time, the only way you can do this with PHP is by creating / using an external application installed / placed on your server and using exec to do this and waiting for a response from the exec, or using the fork_* functions to be able to dip and dive in and out of threads.

like image 35
RobertPitt Avatar answered Nov 15 '22 21:11

RobertPitt