champrock Posted July 8, 2009 Share Posted July 8, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.