Edit report at https://bugs.php.net/bug.php?id=60790&edit=1

 ID:                 60790
 Comment by:         cristian dot marfil at gmail dot com
 Reported by:        leonchuk at gmail dot com
 Summary:            "curl_multi_select" executed first time always one
                     second
 Status:             Feedback
 Type:               Bug
 Package:            cURL related
 Operating System:   windows (XP,7)
 PHP Version:        5.3.9
 Assigned To:        pierrick
 Block user comment: N
 Private report:     N

 New Comment:

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 
pierr...@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);
    }
}


Previous Comments:
------------------------------------------------------------------------
[2012-09-22 13:34:53] pierr...@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-04-03 16:27:11] bompus at gmail dot com

Possibly related to 61141 and 61240

------------------------------------------------------------------------
[2012-03-24 07:28:59] 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-02-28 17:04:37] 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-01-18 13:18:08] 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);



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60790&edit=1

Reply via email to