note 87492 added to function.curl-multi-exec
| From: | manixrock-~-gmail-~-com at osu1 dot php dot net | Date: | Sun, 07 Dec 2008 11:13:46 +0000 |
| Subject: | note 87492 added to function.curl-multi-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147780@lists.php.net to get a copy of this message | ||
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);
?>
You should note the return value of curl_multi_select() is ignored. I found that if you do the
curl_multi_exec() loop only if the return value of curl_multi_select() is != -1 then new links added
to mcurl are ignored. This may be a bug. Hope this saves someone some time.
----
Server IP: 69.147.83.197
Probable Submitter: 78.96.116.14
----
Manual Page -- http://www.php.net/manual/en/function.curl-multi-exec.php
Edit -- https://master.php.net/note/edit/87492
Del: integrated -- https://master.php.net/note/delete/87492/integrated
Del: useless -- https://master.php.net/note/delete/87492/useless
Del: bad code -- https://master.php.net/note/delete/87492/bad+code
Del: spam -- https://master.php.net/note/delete/87492/spam
Del: non-english -- https://master.php.net/note/delete/87492/non-english
Del: in docs -- https://master.php.net/note/delete/87492/in+docs
Del: other reasons-- https://master.php.net/note/delete/87492
Reject -- https://master.php.net/note/reject/87492
Search -- https://master.php.net/manage/user-notes.php