Doc #77682 [NEW]: curl_multi_exec example unnecesary complicated
| From: | daniel at haxx dot se | Date: | Thu, 28 Feb 2019 17:30:31 +0000 |
| Subject: | Doc #77682 [NEW]: curl_multi_exec example unnecesary complicated | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-16438@lists.php.net to get a copy of this message | ||
From: daniel at haxx dot se
Operating system: all
PHP version: master-Git-2019-02-28 (Git)
Package: cURL related
Bug Type: Documentation Problem
Bug description:curl_multi_exec example unnecesary complicated
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 bug report at https://bugs.php.net/bug.php?id=77682&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77682&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77682&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77682&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77682&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77682&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77682&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77682&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77682&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77682&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77682&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77682&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77682&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77682&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77682&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77682&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77682&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77682&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77682&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77682&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77682&r=mysqlcfg