简体   繁体   English

CURLOPT_TIMEOUT 根本不工作 (php)

[英]CURLOPT_TIMEOUT not working at all (php)

I am using curl and setting all the parameters correctly (as far as I know) but CURLOPT_TIMEOUT is being ignored and allowing for an infinite loop.我正在使用 curl 并正确设置所有参数(据我所知)但 CURLOPT_TIMEOUT 被忽略并允许无限循环。 Here is the configuration for my Curl Request:这是我的 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);

I am not the best at debugging so I'm not sure what the problem could be.我不是最擅长调试的,所以我不确定问题出在哪里。 Please help me.请帮我。

The curl_setopt($connection, CURLOPT_TIMEOUT, $seconds) should be called just right before curl_exec() function. 应该在curl_exec()函数之前调用curl_setopt($ connection,CURLOPT_TIMEOUT,$ seconds)。

It wasn't working for me when I called it sooner 当我早点打电话时,它对我不起作用

If your are using CloudFlare note that:如果您使用的是 CloudFlare,请注意:

Enterprise customers can increase the 524 timeout up to 6000 seconds using the proxy_read_timeout API endpoint.企业客户可以使用 proxy_read_timeout API 端点将 524 超时增加到 6000 秒。 If you regularly run HTTP requests that take over 100 seconds to complete (for example large data exports), move those processes behind a subdomain not proxied (grey clouded) in the Cloudflare DNS app.如果您经常运行需要超过 100 秒才能完成的 HTTP 请求(例如大数据导出),请将这些进程移到 Cloudflare DNS 应用程序中未代理的子域(灰色云)后面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM