Bug #72060 [Opn->Wfx]: use curl_multi_*, curl_errno return data not expect

From: Date: Sat, 23 Apr 2016 23:04:05 +0000
Subject: Bug #72060 [Opn->Wfx]: use curl_multi_*, curl_errno return data not expect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200723@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72060&edit=1

 ID:                 72060
 Updated by:         pierrick@php.net
 Reported by:        568089266 at qq dot com
 Summary:            use curl_multi_*,  curl_errno return data not expect
-Status:             Open
+Status:             Wont fix
 Type:               Bug
 Package:            cURL related
 Operating System:   Osx EI 10.11.4
 PHP Version:        5.5.34
 Block user comment: N
 Private report:     N

 New Comment:

There is no way internally to update the errno when the call is triggered with the curl_multi_exec.
The error string is automatically updated by libcurl that's why this one is not an issue.

If you want to get the errno you have to do this :

$info = curl_multi_info_read($mh, $msgs_in_queue);
$errno = $info['result'];


Previous Comments:
------------------------------------------------------------------------
[2016-04-20 02:55:00] 568089266 at qq dot com

Description:
------------
php version 5.5.32
curl 7.37.0 (x86_64-apple-darwin13.0.2) libcurl/7.37.0 OpenSSL/0.9.8} zlib/1.2.5

I found use curl_multi_* methods, if some curl handle connect fail or execute timeout, use
curl_errno function to get the error code, but alway return zero. curl_error function return data is
right;

Test script:
---------------
<?php

//example 1
$mh = curl_multi_init();

$ch1 = curl_init('http://www.some_not_exist_host.com');
curl_setopt($ch1, CURLOPT_TIMEOUT, 3);
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT_MS, 400);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch1, CURLOPT_NOSIGNAL, true);
curl_multi_add_handle($mh, $ch1);

$ch2 = curl_init('http://127.0.0.1');
curl_setopt($ch2, CURLOPT_TIMEOUT, 3);
curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT_MS, 400);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch2, CURLOPT_NOSIGNAL, true);
curl_multi_add_handle($mh, $ch2);

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

    if ($mrc != CURLM_OK){
        break;
    }

    $info = curl_multi_info_read($mh, $msgs_in_queue);
    if ($info !== false){
        $ch = $info['handle'];

        var_dump(curl_error($ch));
        var_dump(curl_errno($ch));    //bug? alway return 0

        curl_multi_remove_handle($mh, $ch);
    }

    if ($active > 0) {
        curl_multi_select($mh, 0.5);
    }

}while ($active);

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


//example 2
echo "----------------", PHP_EOL;
$ch = curl_init('http://www.some_not_exist_host.com');
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 400);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
curl_exec($ch);
var_dump(curl_error($ch));
var_dump(curl_errno($ch));


Expected result:
----------------
string(0) ""
int(0)
string(51) "Could not resolve host: www.some_not_exist_host.com"
int(6)
----------------
string(51) "Could not resolve host: www.some_not_exist_host.com"
int(6)

Actual result:
--------------
string(0) ""
int(0)
string(51) "Could not resolve host: www.some_not_exist_host.com"
int(0)
----------------
string(51) "Could not resolve host: www.some_not_exist_host.com"
int(6)


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



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


Thread (2 messages)

« previous php.bugs (#200723) next »