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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.