Jump to content

CURLOPT_CONNECTTIMEOUT not working properly?


MySQL_Narb

Recommended Posts

Hi there. I've been experiencing some problems regarding the usage of CURLOPT_CONNECTTIMEOUT. Here's part of my basic proxy tester script:

 

while(count($array) < 4){
    $proxy = $proxies[rand(0,count($proxies))];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.REMOVED.org/db/test.php');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1');
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.REMOVED.org');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
    $returned = curl_exec($ch);
    curl_close($ch);
    if($returned == 'success' && !in_array($proxy, $current_proxies)) $array[] = $proxy;
    
}

 

As you can see, the cURL option CURLOPT_CONNECTTIMEOUT is set to four seconds. However, it still spends more than four seconds on attempting to connect with the specified proxy. I even have it returning proxies that were a success which have connection times of around 7-8+ seconds.

 

Any ideas regarding this?

Link to comment
Share on other sites

Your setting the connection time-out as opposed to an execution time-out. How long it takes for a connection to establish is different to how long it takes for a response.

 

The connection could be taking 0.5 seconds to be established whilst the server takes 7 seconds to actually deliver a response. If you were to use the CURL_TIMEOUT option I believe it'll then return false.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.