|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-02-28 17:30 UTC] daniel at haxx dot se
Description: ------------ The example code in the curl_multi_exec documentation is written to work with a very old libcurl version and is therefor much more complicated than it has to be with a libcurl release from the last nine years. Before libcurl 7.20.0 (which was released on Feb 9 2010) it could return CURLM_CALL_MULTI_PERFORM and therefore (PHP) applications needed to consider that. *After* that release however, libcurl never returns that value. I think now, there should be very few users around still with such an old libcurl in use (and those who do use such an old version has a busload of other worse problems to deal with) so I think it is time to reduce the complexity of that example. Mostly because so many users copy that example and run with it. Suggested new example: <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); // set URL and other appropriate options curl_setopt($ch1, CURLOPT_URL, "http://lxr.php.net/"); curl_setopt($ch1, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch2, CURLOPT_HEADER, 0); //create the multiple cURL handle $mh = curl_multi_init(); //add the two handles curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); $active = null; $mrc = CURLM_OK; while ($active && $mrc == CURLM_OK) { $mrc = curl_multi_exec($mh, $active); if($active) { curl_multi_select($mh); } } //close the handles curl_multi_remove_handle($mh, $ch1); curl_multi_remove_handle($mh, $ch2); curl_multi_close($mh); ?> Please bear with me. I'm the main curl author, I am not fluent in PHP. Feel free to edit and clarify the example further. My goal here was to remove the useless and confusing extra loops that are used in the existing documentation for this function. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
Maybe it's better to do it: do { $mrc = curl_multi_exec($mh, $active); if($active) { curl_multi_select($mh); } } while ($active && $mrc == CURLM_OK);