note 115381 added to function.curl-multi-select
| From: | nevil85 at gmail dot com | Date: | Tue, 15 Jul 2014 16:06:15 +0000 |
| Subject: | note 115381 added to function.curl-multi-select | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199936@lists.php.net to get a copy of this message | ||
Even after so many distro releases, in PHP v5.5.9 and libcurl v7.35.0, curl_multi_select still
returns -1. The only work around here is to wait and proceed like nothing ever happened. You have to
determine the "wait" required here.
In my application a very small interval like usleep(1) worked. For example:
<?php
// While we're still active, execute curl
$active = null;
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
// Wait for activity on any curl-connection
if (curl_multi_select($multi) == -1) {
usleep(1);
}
// Continue to exec until curl is ready to
// give us more data
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
?>
Internally php curl_multi_select uses libcurl curl_multi_fdset function and its libcurl
documentation says :
http://curl.haxx.se/libcurl/c/curl_multi_fdset.html
"When libcurl returns -1 in max_fd, it is because libcurl currently does something that
isn't possible for your application to monitor with a socket and unfortunately you can then not
know exactly when the current action is completed using select(). When max_fd returns with -1, you
need to wait a while and then proceed and call curl_multi_perform anyway. How long to wait? I would
suggest 100 milliseconds at least, but you may want to test it out in your own particular conditions
to find a suitable value.
When doing select(), you should use curl_multi_timeout to figure out how long to wait for
action."
Untill PHP implements curl_multi_timeout() we have to play with our application and determine the
"wait".
----
Server IP: 72.52.91.14
Probable Submitter: 14.141.33.202
----
Manual Page -- http://php.net/manual/en/function.curl-multi-select.php
Edit -- https://master.php.net/note/edit/115381
Del: integrated -- https://master.php.net/note/delete/115381/integrated
Del: useless -- https://master.php.net/note/delete/115381/useless
Del: bad code -- https://master.php.net/note/delete/115381/bad+code
Del: spam -- https://master.php.net/note/delete/115381/spam
Del: non-english -- https://master.php.net/note/delete/115381/non-english
Del: in docs -- https://master.php.net/note/delete/115381/in+docs
Del: other reasons-- https://master.php.net/note/delete/115381
Reject -- https://master.php.net/note/reject/115381
Search -- https://master.php.net/manage/user-notes.php