#41598 [Opn->Csd]: Code example for curl_multi_exec doesn't work
| From: | ljbuesch@php.net | Date: | Thu, 07 Jun 2007 01:55:51 +0000 |
| Subject: | #41598 [Opn->Csd]: Code example for curl_multi_exec doesn't work | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969376575@lists.php.net to get a copy of this message | ||
ID: 41598
Updated by: ljbuesch@php.net
Reported By: andrew dot minerd at sellingsource dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Thanks for the diff, tested with my build and ran as expected.
Previous Comments:
------------------------------------------------------------------------
[2007-06-05 18:05:40] andrew dot minerd at sellingsource dot com
Note that the same example is also used on the documentation pages
for:
* curl_multi_add_handle
* curl_multi_close
* curl_multi_init
------------------------------------------------------------------------
[2007-06-05 15:20:19] andrew dot minerd at sellingsource dot com
Patch for a working example:
--- ./test-curl-orig.php 2007-06-05 08:11:31.000000000 -0700
+++ ./test-curl.php 2007-06-05 08:11:05.000000000 -0700
@@ -4,22 +4,26 @@
$ch2 = curl_init();
// set URL and other appropriate options
-curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
-curl_setopt($ch, CURLOPT_HEADER, 0);
-curl_setopt($ch, CURLOPT_URL, "http://www.php.net/");
-curl_setopt($ch, CURLOPT_HEADER, 0);
+curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
+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);
+curl_multi_add_handle($mh, $ch1);
+curl_multi_add_handle($mh, $ch2);
//execute the handles
-curl_multi_exec($mh);
+do {
+ curl_multi_exec($mh, $running);
+} while ($running > 0);
//close the handles
-curl_multi_close();
+curl_multi_remove_handle($ch1);
+curl_multi_remove_handle($ch2);
+curl_multi_close($mh);
?>
------------------------------------------------------------------------
[2007-06-05 15:18:18] andrew dot minerd at sellingsource dot com
Description:
------------
The documentation for curl_multi_exec includes a code example that
doesn't work: it uses undeclared curl handles ($ch rather than $ch1 or
$ch2), only calls curl_multi_exec once (which doesn't complete the
transfer), and doesn't have enough parameters for the curl_multi_exec
call.
Reproduce code:
---------------
See http://php.net/curl_multi_exec
Expected result:
----------------
The contents of http://www.example.com (if it existed) and
http://www.php.net will be downloaded and displayed.
Actual result:
--------------
Notice: Undefined variable: ch in /home/andrewm/test-curl-orig.php on
line 7
Warning: curl_setopt(): supplied argument is not a valid cURL handle
resource in /home/andrewm/test-curl-orig.php on line 7
Notice: Undefined variable: ch in /home/andrewm/test-curl-orig.php on
line 8
Warning: curl_setopt(): supplied argument is not a valid cURL handle
resource in /home/andrewm/test-curl-orig.php on line 8
Notice: Undefined variable: ch in /home/andrewm/test-curl-orig.php on
line 9
Warning: curl_setopt(): supplied argument is not a valid cURL handle
resource in /home/andrewm/test-curl-orig.php on line 9
Notice: Undefined variable: ch in /home/andrewm/test-curl-orig.php on
line 10
Warning: curl_setopt(): supplied argument is not a valid cURL handle
resource in /home/andrewm/test-curl-orig.php on line 10
Warning: curl_multi_exec() expects exactly 2 parameters, 1 given in
/home/andrewm/test-curl-orig.php on line 20
Warning: curl_multi_close() expects exactly 1 parameter, 0 given in
/home/andrewm/test-curl-orig.php on line 23
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41598&edit=1