2011-05-10 71 views
1

我在XAMPP和Windows中使用以下函數。但我不斷收到「致命錯誤:最大執行時間超過30秒」CURLOPT_TIMEOUT不能在php/windows中工作?

任何提示?

function is_404($url) { 
    $handle = curl_init($url); 
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($handle, CURLOPT_TIMEOUT,10); 
    curl_setopt($handle, CURLOPT_CONNECTTIMEOUT,10); 

    /* Get the HTML or whatever is linked in $url. */ 
    $response = curl_exec($handle); 

    /* Check for 404 (file not found). */ 
    $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 
    curl_close($handle); 

    /* If the document has loaded successfully without any redirection or error */ 
    if ($httpCode >= 200 && $httpCode < 300) { 
     return false; 
    } else { 
     return true; 
    } 
} 

回答

0

您的libcurl版本可能存在一個錯誤。也許你可以嘗試升級到更新的版本?

你可以在該系統上(在特定的URL上)運行curl命令行工具來調試會發生什麼?如果可以的話,使用-v或--trace-ascii選項應該很有價值,可以準確顯示捲曲是幹什麼和不幹的。

您的代碼應該像寫入一樣工作。

+0

謝謝!事實證明,我在一次調用中檢查了太多網址,因此我達到了php的時間限制。現在將其設置爲0。 – giorgio79 2011-05-10 07:20:01