加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

CURLOPT_TIMEOUT根本不工作(php)

发布时间:2020-12-13 22:53:33 所属栏目:PHP教程 来源:网络整理
导读:我正在使用curl并正确设置所有参数(据我所知),但CURLOPT_TIMEOUT被忽略并允许无限循环.这是我的卷曲请求的配置: $user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';$options = array( CURLOPT_CUSTOMREQUEST = "GET",//set
我正在使用curl并正确设置所有参数(据我所知),但CURLOPT_TIMEOUT被忽略并允许无限循环.这是我的卷曲请求的配置:

$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).

当我早点打电话时,它对我不起作用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读