gpt4 book ai didi

php - CURLOPT_TIMEOUT 根本不工作 (php)

转载 作者:可可西里 更新时间:2023-10-31 23:30:51 24 4
gpt4 key购买 nike

我正在使用 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)。

当我更早调用它时它对我不起作用

关于php - CURLOPT_TIMEOUT 根本不工作 (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25735359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com