1
  • continue on php curl 10 seconds timeout

  • code

    <?php
    $directory = 'http://www.google1.com';  
    $returntransfer = true;
    $connecttimeout = 10;
    timeout = 10; 
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $directory);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, $returntransfer);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connecttimeout);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    
    sleep(10); //wait 10 sec on browser
    
    $execute = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);
    curl_close($ch);
    
    if ($curl_errno > 0) {
        echo "cURL Error ($curl_errno): $curl_error\n";
    }
    ?>
    
  • From the above code, my questions is the following:
    (1) When I use the sleep(), it will wait 10 seconds on the web page but the CURL_CONNECTTIMEOUT and CURLOPT_TIMEOUT seems nothing happened? Why?
    (2) How do I know that the CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT is set?

2
  • What are you trying to achieve? Your former question was looking to wait for 10 secs in a browser. You achieved that. What do you mean by "nothing happened"? It may help switching $directory = 'http://www.google1.com'; to $directory = 'http://www.google.com'; Commented Jan 6, 2015 at 23:19
  • @HansZ. How about I set the both timeout to 5 seconds? Commented Jan 7, 2015 at 1:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.