簡體   English   中英

CURLOPT_TIMEOUT 根本不工作 (php)

[英]CURLOPT_TIMEOUT not working at all (php)

我正在使用 curl 並正確設置所有參數(據我所知)但 CURLOPT_TIMEOUT 被忽略並允許無限循環。 這是我的 Curl 請求的配置:

$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(

        CURLOPT_CUSTOMREQUEST => "GET", //set request type post or get

        CURLOPT_POST => false, //set to GET

        CURLOPT_USERAGENT => $user_agent, //set user agent

        CURLOPT_COOKIEFILE => dirname(__FILE__)."/cookie.txt", //set cookie file

        CURLOPT_COOKIEJAR => dirname(__FILE__)."/cookie.txt", //set cookie jar

        CURLOPT_RETURNTRANSFER => true, // return web page

        CURLOPT_SSL_VERIFYPEER, FALSE, //ignore ssl

        CURLOPT_PROXY =>$proxy['ip'],

        CURLOPT_PROXYPORT =>$proxy['port'],

        CURLOPT_HEADER => false, // don't return headers

        CURLOPT_FOLLOWLOCATION => true, // follow redirects

        CURLOPT_ENCODING => "", // handle all encodings

        CURLOPT_AUTOREFERER => true, // set referrer on redirect

        CURLOPT_CONNECTTIMEOUT => 20, // timeout on connect

        CURLOPT_TIMEOUT => 10, // timeout on response

        CURLOPT_MAXREDIRS => 10, // stop after 10 redirects

    );
    $ch = curl_init($url);

    curl_setopt_array($ch, $options);

    $content = curl_exec($ch);

    $err = curl_errno($ch);

    $errmsg = curl_error($ch);

    $header = curl_getinfo($ch);
    curl_close($ch);

我不是最擅長調試的,所以我不確定問題出在哪里。 請幫我。

應該在curl_exec()函數之前調用curl_setopt($ connection,CURLOPT_TIMEOUT,$ seconds)。

當我早點打電話時,它對我不起作用

如果您使用的是 CloudFlare,請注意:

企業客戶可以使用 proxy_read_timeout API 端點將 524 超時增加到 6000 秒。 如果您經常運行需要超過 100 秒才能完成的 HTTP 請求(例如大數據導出),請將這些進程移到 Cloudflare DNS 應用程序中未代理的子域(灰色雲)后面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM