Doc #77682 [Opn->Csd]: curl_multi_exec example unnecesary complicated

From: Date: Thu, 28 Feb 2019 22:06:07 +0000
Subject: Doc #77682 [Opn->Csd]: curl_multi_exec example unnecesary complicated
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16440@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77682&edit=1 ID: 77682 Updated by: salathe@php.net Reported by: daniel at haxx dot se Summary: curl_multi_exec example unnecesary complicated -Status: Open +Status: Closed Type: Documentation Problem Package: cURL related Operating System: all PHP Version: master-Git-2019-02-28 (Git) -Assigned To: +Assigned To: salathe Block user comment: N Private report: N New Comment: The fix for this bug has been committed. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. I have updated the examples with loops like the do/while that you suggested, Daniel. Thanks for the push in the right direction! There is a bunch of tidying up, clarifications, and so on, still to be done for the curl_multi_* functions. They are a common source of confusion and questions, for sure, and anything we can do to make the docs clearer is much needed. Previous Comments: ------------------------------------------------------------------------ [2019-02-28 22:00:17] salathe@php.net Automatic comment from SVN on behalf of salathe Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=346933 Log: improve curl_multi_exec() loops (doc #77682) curl_multi_exec() hasn't returned CURLM_CALL_MULTI_PERFORM for a loooong time (it stopped doing so as of libcurl 7.20.0, which was released on Feb 9 2010). Thanks to Daniel Stenberg for the details. ------------------------------------------------------------------------ [2019-02-28 17:34:29] daniel at haxx dot se 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); ------------------------------------------------------------------------ [2019-02-28 17:30:31] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77682&edit=1

« previous php.doc.bugs (#16440) next »