CURLOPT_TIMEOUT not working in php / windows?

醉酒当歌 提交于 2019-12-11 10:39:37

问题


I am using the following function with XAMPP and Windows. But I keep getting "Fatal error: Maximum execution time of 30 seconds exceeded "

Any tips?

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;
    }
}

回答1:


There might be a bug in your version of libcurl. Perhaps you can try to upgrade to a more recent version?

Can you run the curl command line tool on that system (on the particular URL) to debug what happens? If you can, using the -v or --trace-ascii options should be valuable to show exactly what curl does and doesn't.

Your code is supposed to work just as written.



来源:https://stackoverflow.com/questions/5944032/curlopt-timeout-not-working-in-php-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!