CURLOPT_TIMEOUT not working at all (php)
Asked Answered
C

2

6

I am using curl and setting all the parameters correctly (as far as I know) but CURLOPT_TIMEOUT is being ignored and allowing for an infinite loop. Here is the configuration for my Curl Request:

$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(

        CURLOPT_CUSTOMREQUEST => "GET", //set request type post or get

        CURLOPT_POST => false, //set to GET

        CURLOPT_USERAGENT => $user_agent, //set user agent

        CURLOPT_COOKIEFILE => dirname(__FILE__)."/cookie.txt", //set cookie file

        CURLOPT_COOKIEJAR => dirname(__FILE__)."/cookie.txt", //set cookie jar

        CURLOPT_RETURNTRANSFER => true, // return web page

        CURLOPT_SSL_VERIFYPEER, FALSE, //ignore ssl

        CURLOPT_PROXY =>$proxy['ip'],

        CURLOPT_PROXYPORT =>$proxy['port'],

        CURLOPT_HEADER => false, // don't return headers

        CURLOPT_FOLLOWLOCATION => true, // follow redirects

        CURLOPT_ENCODING => "", // handle all encodings

        CURLOPT_AUTOREFERER => true, // set referrer on redirect

        CURLOPT_CONNECTTIMEOUT => 20, // timeout on connect

        CURLOPT_TIMEOUT => 10, // timeout on response

        CURLOPT_MAXREDIRS => 10, // stop after 10 redirects

    );
    $ch = curl_init($url);

    curl_setopt_array($ch, $options);

    $content = curl_exec($ch);

    $err = curl_errno($ch);

    $errmsg = curl_error($ch);

    $header = curl_getinfo($ch);
    curl_close($ch);

I am not the best at debugging so I'm not sure what the problem could be. Please help me.

Carswell answered 9/9, 2014 at 1:13 Comment(7)
which version of CUrl are you using. Try using CURLOPT_CONNECTTIMEOUT_MS if version >= 7.16.2. You can check the version using <?php phpinfo(); ?>Function
I tried to use CURLOPT_CONNECTTIMEOUT_MS but im still getting an infinite loopCarswell
Might be unrelated but in your code is this: CURLOPT_SSL_VERIFYPEER, FALSE, //ignore ssl - intentional?Conchita
Because if so it should be CURLOPT_SSL_VERIFYPEER => FALSE, //ignore sslConchita
@user3284327 also try after setting CURLOPT_FOLLOWLOCATION to falseFunction
I did make that SSL fix and i changed followlocation and still no diceCarswell
I was never able to figure out the problem. Is anyone able to help. let me know what you needCarswell
B
4

The curl_setopt($connection, CURLOPT_TIMEOUT, $seconds) should be called just right before curl_exec() function.

It wasn't working for me when I called it sooner

Border answered 4/3, 2016 at 17:14 Comment(1)
Any documentation surrounding this? This doesn't seem right to me... Unless some other code you hadn't noticed was changing the option, I would expect any CURLOPT_* value to be set on a resource object returned by curl_init(), to stick.Crosse
P
1

If your are using CloudFlare note that :

Enterprise customers can increase the 524 timeout up to 6000 seconds using the proxy_read_timeout API endpoint. If you regularly run HTTP requests that take over 100 seconds to complete (for example large data exports), move those processes behind a subdomain not proxied (grey clouded) in the Cloudflare DNS app.

Patino answered 11/4, 2022 at 11:53 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.