Kevin
Kevin

Reputation: 1000

Why my curl connect_time is always equal to 0?

I'm trying to test some SOCKS proxy, and when trying to get the "ping" time of this proxy, I'm looking for the variable "connect_time". For HTTP and HTTPS proxy, this seems to working fine, but not for SOCKS (SOCKS4 or SOCKS5) proxy where the connect_time is always equal to 0 (or almost...) !

{
"url":"XXX",
"content_type":"text/html",
"http_code":200,
"header_size":178,
"request_size":379,
"filetime":-1,
"ssl_verify_result":0,
"redirect_count":0,
"total_time":4.738683,
"namelookup_time":0.000021,
"connect_time":0.000023,
"pretransfer_time":0.000104,
"size_upload":140,
"size_download":51275,
"speed_download":10820,
"speed_upload":29,
"download_content_length":-1,
"upload_content_length":140,
"starttransfer_time":0.000149,
"redirect_time":0,
"certinfo":{
},
"redirect_url":""
}

Here is a piece of my code :

$options = array(
        CURLOPT_PROXY          => $proxy->ip.':'.$proxy->port,
        CURLOPT_TIMEOUT        => 30,
        CURLOPT_CONNECTTIMEOUT => 30,
        CURLOPT_HEADER         => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER     => array('Expect:'),
        CURLOPT_SSL_VERIFYHOST     => false,
        CURLOPT_SSL_VERIFYPEER     => false,
        CURLOPT_VERBOSE         => FALSE,
        CURLOPT_USERAGENT         => 'XXX',
);

if ($proxy->type == 'https')
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
elseif ($proxy->type == 'socks4')
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
elseif ($proxy->type == 'socks5')
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

When trying to ping (with ping...) this proxy from my computer, I've a ping time of about 50ms...

Is there a bug with curl or php ? Do you know can I retrieve the correct ping time ?

Upvotes: 8

Views: 839

Answers (1)

Benjamin de Bos
Benjamin de Bos

Reputation: 4346

When using a proxy, the connect time is the time between the first response of the proxy and the end authentication. So basically your authentication process takes about 0.00023 seconds. Which is quite plausible.

I'm not sure if this is the intended way of how cURL should work because it looks like this is only the case when using proxies on cURL.

I'd consider it a bug.

Upvotes: 2

Related Questions