天天看點

curl php timeout,CURLOPT_TIMEOUT根本不工作(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 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,curl,timeout,infinite-loop

來源: https://codeday.me/bug/20190708/1403641.html