php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72060 use curl_multi_*, curl_errno return data not expect
Submitted: 2016-04-20 02:55 UTC Modified: 2016-04-23 23:04 UTC
From: 568089266 at qq dot com Assigned:
Status: Wont fix Package: cURL related
PHP Version: 5.5.34 OS: Osx EI 10.11.4
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 568089266 at qq dot com
New email:
PHP Version: OS:

 

 [2016-04-20 02:55 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-23 23:04 UTC] pierrick@php.net
-Status: Open +Status: Wont fix
 [2016-04-23 23:04 UTC] pierrick@php.net
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'];
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC