note 99052 added to function.curl-multi-select

From: Date: Sat, 24 Jul 2010 15:33:03 +0000
Subject: note 99052 added to function.curl-multi-select
Groups: php.notes 
Request: Send a blank email to php-notes+get-171101@lists.php.net to get a copy of this message
Since the docs are still lacking, here's an example of how to use the function. The following code will keep checking all active threads until one of them returns the HTTP 200 Ok status code, or simply end. On success, it will return the URL that worked. <?php $running=null; do { curl_multi_exec($mh,$running); $ready=curl_multi_select($mh); // this will pause the loop if($ready>0){ while($info=curl_multi_info_read($mh)){ $status=curl_getinfo($info['handle'],CURLINFO_HTTP_CODE); if($status==200){ $successUrl=curl_getinfo($info['handle'],CURLINFO_EFFECTIVE_URL); break 2; } } } } while ($running>0 && $ready!=-1); ?> The question for the $ready variable is, if it will return the value before or after the timeout has occurred. From my tests it appears that it will return the value immediately, and only then pause the execution. That's because it's always zero the first time through the loop, even if the time limit is as high as 10sec. I've expected it to wait and only then return the value so that came unexpected to me. As stated by someone else, it also doesn't seem to return the overall count of threads in the handle, but only that of the currently active ones. ---- Server IP: 212.124.37.9 Probable Submitter: 109.192.68.60 ---- Manual Page -- http://www.php.net/manual/en/function.curl-multi-select.php Edit -- https://master.php.net/note/edit/99052 Del: integrated -- https://master.php.net/note/delete/99052/integrated Del: useless -- https://master.php.net/note/delete/99052/useless Del: bad code -- https://master.php.net/note/delete/99052/bad+code Del: spam -- https://master.php.net/note/delete/99052/spam Del: non-english -- https://master.php.net/note/delete/99052/non-english Del: in docs -- https://master.php.net/note/delete/99052/in+docs Del: other reasons-- https://master.php.net/note/delete/99052 Reject -- https://master.php.net/note/reject/99052 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171101) next »