0

I want to download multiple files (at the same time) from array of urls in php

Example :

$array = array(
    "http://mysite.com/a1.zip",
    "http://mysite.com/a2.zip",
    "http://mysite.com/a3.zip",
    "http://mysite.com/a4.zip",
    "http://mysite.com/a5.zip"
);

I want to download above mentioned file to the below mentioned path without using foreach i want to download them simultaneously in php..

$to_file_path = "http://www.mysite.com/downloaded";

if($to_file_path)

///it should return after copying all the files to the new path

echo 'successful';

i was sure that curl can do this but please anybody create some simple example for me bcoz i am not very much familiar with curl..

Please a little help will be appreciated..

Hey it is not actually duplicate, my logic is far different i want to download multiple files at a same time without waiting one file to complete this way we can utilize the full power of server and it can save our time.. kindly help me.. i badly need this..

i can download it one by one with

foreach($array as $filename){

copy($filename,$to_file_path.basename($filename))

}

but it sucks so much time it download each file seperately but i want to download all the files mentioned in the array simultaneously..

Please Help.. a sample coding in comment is appreciated.. Thanks

  • 1
    Did you RTFM? PHP has a function for that and there's examples of how to use it on the link below. [1]: http://php.net/manual/en/function.curl-multi-exec.php – symcbean Mar 29 '13 at 21:54
  • Use `curl_multi_init` see example : http://stackoverflow.com/questions/12891689/php-fastest-way-to-check-presence-of-text-in-many-domains-above-1000 – Baba Mar 29 '13 at 21:56

0 Answers0