php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41598 Code example for curl_multi_exec doesn't work
Submitted: 2007-06-05 15:18 UTC Modified: 2007-06-07 01:55 UTC
From: andrew dot minerd at sellingsource dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrew dot minerd at sellingsource dot com
New email:
PHP Version: OS:

 

 [2007-06-05 15:18 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-05 15:20 UTC] 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 18:05 UTC] 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-07 01:55 UTC] ljbuesch@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 06 18:00:03 2025 UTC