php.net |  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
Votes:1
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 - 18 = ?
Subscribe to this entry?

 
 [2013-02-11 19:48 UTC] divinity76 at gmail dot com
Description:
------------
as of writing, the example code for curl_multi_close is

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

// set URL and other appropriate options
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);

$running=null;
//execute the handles
do {
    curl_multi_exec($mh,$running);
} while ($running > 0);

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

?>

i believe this code will be stuck using all cpu it can on 
do{curl_multi_exec($mh,$running);}while($running>0);
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-13 21:25 UTC] cataphract@php.net
-Type: Feature/Change Request +Type: Bug
 [2013-10-09 06:59 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2013-10-09 06:59 UTC] krakjoe@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC