码
<?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_CONNECTTIMEOUT
和CURLOPT_TIMEOUT
似乎什么也没发生?为什么呢?
(2)我如何知道CURLOPT_CONNECTTIMEOUT
和CURLOPT_TIMEOUT
已设定?