#1
  1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Waterloo, Ontario, Canada
    Posts
    609
    Rep Power
    0

    CURLOPT_TIMEOUT option for curl calls isn't being obeyed


    I've included the lib I'm using:

    PHP Code:
    <?php

        
    class CustomCurl implements ICustomCurl {
            var 
    $headers;
            var 
    $user_agent;
            var 
    $compression;

            var 
    $info;

            function 
    CustomCurl($compression "gzip") {
                
    // added image/x-icon because stupid http://www.msnbc.msn.com/favicon.ico sends back a weird mime type
                
    $this->headers[]     =    "Accept: image/gif, image/x-icon, image/x-bitmap, image/jpeg, image/png, image/pjpeg, text/html";
                
    $this->headers[]     =    "Connection: Keep-Alive";
                
    $this->headers[]     =    "Accept-Language: en-us,en;q=0.5";
                
    $this->headers[]     =    "Content-type: application/x-www-form-urlencoded;charset=UTF-8";
                
    $this->headers[]     =    "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)";

                
    $this->user_agent    =    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)";

                
    $this->compression   =    $compression;
            }
            function 
    getInfo($option "") {
                return 
    $option==="" $this->info : (in_array($option,$this->info) ? $this->info[$option] : $this->info);
            }
            function 
    get($url) {
                
    $process    =    curl_init($url);
                
    curl_setopt($process,CURLOPT_HTTPHEADER,$this->headers);
                
    curl_setopt($process,CURLOPT_HEADER,false);
                
    curl_setopt($process,CURLOPT_USERAGENT,$this->user_agent);

                
    curl_setopt($process,CURLOPT_ENCODING,$this->compression);

                
    // time allowed to connect to server
                
    curl_setopt($process,CURLOPT_CONNECTTIMEOUT,5);

                
    // time allowed to process curl call
                
    curl_setopt($process,CURLOPT_TIMEOUT,2);

                
    // for https; don't verify certificate
                
    curl_setopt($process,CURLOPT_SSL_VERIFYPEER,false);
    //            curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
                
    curl_setopt($process,CURLOPT_SSL_VERIFYHOST,1);
                
    curl_setopt($process,CURLOPT_FRESH_CONNECT,true);

                
    curl_setopt($process,CURLOPT_RETURNTRANSFER,true);
                
    curl_setopt($process,CURLOPT_FOLLOWLOCATION,true);
                
    curl_setopt($process,CURLOPT_MAXREDIRS,3);

                
    $return        =    curl_exec($process);
                
    $this->info    =    curl_getinfo($process);
                
    curl_close($process);
                return 
    $return;
            }
            function 
    error($error) {
                echo 
    "<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>cURL Error</b><br>$error</div></center>";
                die;
            }
        }

    ?>
    The CURLOPT_TIMEOUT isn't being obeyed. Any thoughts? It's hard to test; I normally go on reddit, click on 40 links for tabs, and find one that isn't loading cause of a traffic overload.

    Right now, http://donklephant.com/2009/04/20/quote-of-the-day-weakness/ isn't working, so it's good to test.

    Thanks for any thoughts.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Waterloo, Ontario, Canada
    Posts
    609
    Rep Power
    0
    I've tested with these as well, but no dice:


    curl_setopt($process,CURLOPT_LOW_SPEED_LIMIT,10000);
    curl_setopt($process,CURLOPT_LOW_SPEED_TIME,5);

    This should limit the execution to 5 seconds when the bandwidth coming in is less than 10k (10 000 bytes).

    Hmmm. Looking for any solution to stopping the call if the requesting server hangs.
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Waterloo, Ontario, Canada
    Posts
    609
    Rep Power
    0
    bump.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Waterloo, Ontario, Canada
    Posts
    609
    Rep Power
    0
    bump.
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Waterloo, Ontario, Canada
    Posts
    609
    Rep Power
    0
    bump.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    I found the solution


    Just figured this out if anyone still cares...

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

    It wasn't working for me when I called it sooner
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0
    I still care. Thanks - that was the problem. Unbelievable.

    Originally Posted by edigi
    Just figured this out if anyone still cares...

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

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

IMN logo majestic logo threadwatch logo seochat tools logo