note 108928 added to function.curl-multi-select
| From: | vigo dot von dot harrach at gmx dot de | Date: | Wed, 06 Jun 2012 10:53:31 +0000 |
| Subject: | note 108928 added to function.curl-multi-select | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188415@lists.php.net to get a copy of this message | ||
curl_multi_select($mh, $timeout) simply blocks for $timeout seconds while curl_multi_exec() returns
CURLM_CALL_MULTI_PERFORM. Otherwise, it works as intended, and blocks until at least one connection
has completed or $timeout seconds, whatever happens first.
For that reason, curl_multi_exec() should always be wrapped:
function full_curl_multi_exec($mh, &$still_running) {
do {
$rv = curl_multi_exec($mh, $still_running);
} while ($rv == CURLM_CALL_MULTI_PERFORM);
return $rv;
}
With that, the core of "multi" processing becomes (ignoring error handling for brevity):
full_curl_multi_exec($mh, $still_running); // start requests
do { // "wait for completion"-loop
curl_multi_select($mh); // non-busy (!) wait for state change
full_curl_multi_exec($mh, $still_running); // get new state
while ($info = curl_multi_info_read($mh)) {
// process completed request (e.g. curl_multi_getcontent($info['handle']))
}
} while ($still_running);
Note that after starting requests, retrieval is done in the background - one of the better shots at
parallel processing in PHP.
----
Server IP: 87.106.1.137
Probable Submitter: 217.7.231.86
----
Manual Page -- http://www.php.net/manual/en/function.curl-multi-select.php
Edit -- https://master.php.net/note/edit/108928
Del: integrated -- https://master.php.net/note/delete/108928/integrated
Del: useless -- https://master.php.net/note/delete/108928/useless
Del: bad code -- https://master.php.net/note/delete/108928/bad+code
Del: spam -- https://master.php.net/note/delete/108928/spam
Del: non-english -- https://master.php.net/note/delete/108928/non-english
Del: in docs -- https://master.php.net/note/delete/108928/in+docs
Del: other reasons-- https://master.php.net/note/delete/108928
Reject -- https://master.php.net/note/reject/108928
Search -- https://master.php.net/manage/user-notes.php