php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61240 curl_multi_select cause cpu load 100%
Submitted: 2012-03-02 08:51 UTC Modified: 2012-09-22 13:29 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: niniwzw at qq dot com Assigned: pierrick (profile)
Status: Not a bug Package: cURL related
PHP Version: 5.3.10 OS: window xp
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: niniwzw at qq dot com
New email:
PHP Version: OS:

 

 [2012-03-02 08:51 UTC] niniwzw at qq dot com
Description:
------------
---
From manual page: http://www.php.net/function.curl-multi-exec
---
In the document of curl_multi_exec, has a example in the document.
it can run in php 5.2, but php 5.3 and php 5.4 cause cpu load 100%.

the example is:
<?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;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

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

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-03 16:27 UTC] bompus at gmail dot com
Related to 60790 and 61141
 [2012-04-05 02:01 UTC] niniwzw at qq dot com
the best solution work without the curl_multi_select may be this:
<?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;
$exec_count = 0;
do {
	$mrc = curl_multi_exec($mh, $active);
	usleep(1);
	$exec_count++;
} while ($mrc == CURLM_CALL_MULTI_PERFORM || ($active && $mrc == CURLM_OK));

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

var_dump($exec_count);
?>
I scan the source code of curl_multi_select, there was no change from php 5.2.17 to 5.3.10, may be it's the problem of libcurl(curl_multi_fdset, fuction)
 [2012-09-22 13:29 UTC] pierrick@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: pierrick
 [2012-09-22 13:29 UTC] pierrick@php.net
This is not a bug. This behaviour is due to the same reason as bug #61141 (cf my 
comment on this bug).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 08:01:29 2025 UTC