php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60790 "curl_multi_select" executed first time always one second
Submitted: 2012-01-18 13:18 UTC Modified: 2013-02-18 00:35 UTC
Votes:7
Avg. Score:4.9 ± 0.3
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:6 (85.7%)
From: leonchuk at gmail dot com Assigned: pierrick (profile)
Status: No Feedback Package: cURL related
PHP Version: 5.3.9 OS: windows (XP,7)
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: leonchuk at gmail dot com
New email:
PHP Version: OS:

 

 [2012-01-18 13:18 UTC] leonchuk at gmail dot com
Description:
------------
In Windows (tested XP and w7) function "curl_multi_select" executed first time always one second (equal to default parameter - $timeout)

---
From manual page: http://www.php.net/function.curl-multi-init#refsect1-function.curl-multi-init-examples
---


Test script:
---------------
$ch1 = curl_init();
curl_setopt_array($ch1, array(CURLOPT_URL=>"http://lxr.php.net/", CURLOPT_HEADER=>0, CURLOPT_RETURNTRANSFER=>1));
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);

$active = null;
do $mrc = curl_multi_exec($mh, $active);
while ($mrc == CURLM_CALL_MULTI_PERFORM);

$start_time = microtime(true);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) { #after first run = 1 sec
        echo (microtime(true)-$start_time)."<br>".PHP_EOL; 
        do $mrc = curl_multi_exec($mh, $active);
        while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

curl_multi_remove_handle($mh, $ch1); curl_multi_close($mh);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-28 17:04 UTC] bompus at gmail dot com
I've noticed this as well. The function should return as soon as it is finished I 
believe. This could be a CURL issue or a PHP issue. I'm interested to hear what 
the dev's say since I've had all kinds of issues with curl_multi_select in newer 
PHP versions. I keep having to revert to 5.3.6.. I've tried 5.3.10 and using 
curl_multi_select within a loop checking for != -1 and it causes an infinite loop 
since it always returns -1 on Windows 7 x64/x86, PHP 5.3.10
 [2012-03-24 07:28 UTC] qiwei dot mo at gmail dot com
I have the same problem white them.
Env: win7 + php5.4.0

Use the code as curl_multi-exec
http://cn2.php.net/manual/zh/function.curl-multi-exec.php
cause the final error: Fatal error: Maximum execution time of 30 seconds 
exceeded. But it be runing well in php5.3.6

In PHP5.4 , when i replace the under code
-----------------------------------
$active = null;
// 执行批处理句柄
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);
    }
}
--------------------------------------
With

do {
	curl_multi_exec($hMultiCurl, $iRunning);
} while ($iRunning > 0);
-------------------------------------

the programe run ok

So the question is the curl_multi_select bug , cause the while infinite loop.
 [2012-04-03 16:27 UTC] bompus at gmail dot com
Possibly related to 61141 and 61240
 [2012-09-22 13:34 UTC] pierrick@php.net
-Status: Open +Status: Feedback
 [2012-09-22 13:34 UTC] pierrick@php.net
This behavior is probably related to Bug #61141. Can you try this script 

$ch1 = curl_init();
curl_setopt_array($ch1, array(CURLOPT_URL=>"http://lxr.php.net/", 
CURLOPT_HEADER=>0, CURLOPT_RETURNTRANSFER=>1));
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);

$active = null;
do $mrc = curl_multi_exec($mh, $active);
while ($mrc == CURLM_CALL_MULTI_PERFORM);

$start_time = microtime(true);

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

curl_multi_remove_handle($mh, $ch1); curl_multi_close($mh);

And let me know if you still have your problem ?
 [2012-09-22 13:35 UTC] pierrick@php.net
-Assigned To: +Assigned To: pierrick
 [2012-12-13 16:43 UTC] cristian dot marfil at gmail dot com
Works for me!

// jlcooke - thanks to http://technosophos.com/content/connection-sharing-curl-
php-how-re-use-http-connections-knock-70-rest-network-time
// https://forums.aws.amazon.com/thread.jspa?messageID=397448
class RequestCore {
    public static $curl_multi_handle = null;
    public static function curlExecUsingMulti($curl_handle) {
		set_time_limit(1); //Test
        // Create a multi if necessary.
        if (empty(RequestCore::$curl_multi_handle)) {
            RequestCore::$curl_multi_handle = curl_multi_init();
        }

        // Add the handle to be processed.
        curl_multi_add_handle(RequestCore::$curl_multi_handle, $curl_handle);

        // Do all the processing.
        $active = NULL;
        do {
            $ret = curl_multi_exec(RequestCore::$curl_multi_handle, $active);
        } while ($ret == CURLM_CALL_MULTI_PERFORM);

        while ($active && $ret == CURLM_OK) {
			//FIX https://bugs.php.net/bug.php?id=60790&edit=1 by 
pierrick@php.net
			if (curl_multi_select(RequestCore::$curl_multi_handle) 
== -1) {
				usleep(100);
			}
            //if (curl_multi_select(RequestCore::$curl_multi_handle) != -1) {
                    do {
                            $mrc = 
curl_multi_exec(RequestCore::$curl_multi_handle, $active);
                    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
            //}
        }


        // Remove the handle from the multi processor.
        curl_multi_remove_handle(RequestCore::$curl_multi_handle, $curl_handle);

        return curl_multi_getcontent($curl_handle);
    }
}
 [2012-12-13 20:17 UTC] leonchuk at gmail dot com
Thanks pierrick, marfil for answers.
But, your codes still dont work:(

I found the answer by putting the following code: 

...
while ($mrc == CURLM_CALL_MULTI_PERFORM);
#fix
if(strtoupper(substr(PHP_OS,0,3)) === 'WIN'){
  curl_multi_select($this->m_handle, 0.005);
  curl_multi_exec($this->m_handle, $active);
}
...
 [2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC