The return value of curl_exec($ch) is always false, and calling curl_errno($ch) is empty? ? ?
public function http_curl($url,$type='get',$res='json',$arr=''){
// 初始化
$ch=curl_init();
// 设置参数
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HEADER,FALSE);
if($type == 'post'){
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$arr);
}
$output=curl_exec($ch);
curl_close($ch);
var_dump($output);
echo 'error:'.curl_errno($ch);
if(curl_errno($ch)){
var_dump(curl_errno($ch));
}
if($res == 'json'){
return json_decode($output,true);
}
return $output;
}
What should I do if my curl_init returns empty?
Thanks for the invitation!
curl_errno($ch) You have closed the handle before, change the order and then print.
It would be strange to still get errors after closing the connection. . Get the error before curl_close