php curl 10秒超时(第2部分)

时间:2015-01-06 22:52:03

标签: php curl

  • 继续php curl 10 seconds timeout

  • <?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";
    }
    ?>
    
  • 从上面的代码中,我的问题如下:
    (1)当我使用sleep()时,它会在网页上等待10秒,但CURL_CONNECTTIMEOUTCURLOPT_TIMEOUT似乎什么也没发生?为什么呢?
    (2)我如何知道CURLOPT_CONNECTTIMEOUTCURLOPT_TIMEOUT已设定?

0 个答案:

没有答案