|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64191 "curl_multi_close" example code needlessly use 100% cpu..
Submitted: 2013-02-11 19:48 UTC Modified: 2013-10-09 06:59 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: divinity76 at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2013-02-11 19:48 UTC] divinity76 at gmail dot com
as of writing, the example code for curl_multi_close is

// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles

//execute the handles
do {
} while ($running > 0);

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);


i believe this code will be stuck using all cpu it can on 
part, until both curl handles are done..  and i believe a solution is 
curl_multi_select ; there already is example codes on curl_multi_exec / 
curl_multi_init that use curl_multi_select to do non-busy-waiting (or whatever 
it's called, idk), maybe copy&paste the example code from 1 of those?

Expected result:
small cpu usage

Actual result:
high cpu usage


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-13 21:25 UTC]
-Type: Feature/Change Request +Type: Bug
 [2013-10-09 06:59 UTC]
-Status: Open +Status: Not a bug
 [2013-10-09 06:59 UTC]
Examples in the documentation are not intended to show best practices, but illustrate functionality: they are *meant* to be simple.

I therefore do not see a reason to change the example, lets keep it simple :)
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 23 16:01:23 2021 UTC