Jump to content

PHP curl : download 5files at a time always


champrock

Recommended Posts

HI

 

I have a list of files to be downloaded. I had earlier planned to use curlmulti and download 5files at a time using that. But they vary greatly in their sizes so curlmulti will not be of much use because if one file is big and the  rest of the 4files are finished then the script will simply wait for the bigger file to complete.

 

I came across this code on php.net http://in.php.net/manual/en/function.curl-multi-exec.php page which supposedly does this:

For anyone trying to dynamically add links to mcurl and removing them as they complete (for example to keep a constant of 5 links downloading), I found that the following code works:

<?php
$mcurl = curl_multi_init();
for(; {
    curl_multi_select($mcurl);
    while(($mcRes = curl_multi_exec($mcurl, $mcActive)) == CURLM_CALL_MULTI_PERFORM);
    if($mcRes != CURLM_OK) break;
    while($done = curl_multi_info_read($mcurl)) {
        // code that parses, adds or removes links to mcurl
    }
    // here you should check if all the links are finished and break, or add new links to the loop
}
curl_multi_close($mcurl);
?> 

I am unable to figure out how to get it to work. I dont know what the functions CURLM_CALL_MULTI_PERFORM , $mcActive etc mean. Can anyone please guide me on how to download 5files simultaneously and automatically start another instance of curl as soon as one of them is completed?

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.