首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何显示PHP-cURL错误?

如何显示PHP-cURL错误?
EN

Stack Overflow用户
提问于 2021-06-21 16:32:27
回答 1查看 84关注 0票数 0

页面无法加载的原因可能是什么?我目前正在向我的机器人发送一个请求,它会给我发回一个响应,但不知何故,如果机器人在线并工作,页面就不会加载。有没有办法得到这个错误?我有一个cPanel,display_errors是1。还有其他想法吗?

这是我的一个要求:

代码语言:javascript
复制
function getData($Id) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"http://IPAdress:8000/Data/".$Id);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    $server_output = curl_exec($ch);
    curl_close ($ch);

   return $server_output;
}
EN

回答 1

Stack Overflow用户

发布于 2021-06-21 16:42:03

curl_errno()和curl_error()通常就足够了,

代码语言:javascript
复制
$server_output = curl_exec($ch);
$errstr=null;
if(curl_errno($ch)){
    $errstr = curl_errno($ch).": ".curl_error($ch);
}
curl_close ($ch);
if(isset($errstr)){
    echo $errstr;
}

有时,您可以通过添加CURLOPT_VERBOSE来获取更多信息

代码语言:javascript
复制
$stderrh=tmpfile();
curl_setopt_array($ch,array(CURLOPT_VERBOSE=>1,CURLOPT_STDERR=>$stderrh));
$server_output = curl_exec($ch);
/* https://bugs.php.net/bug.php?id=76268 */
rewind($stderrh); 
$stderr=stream_get_contents($stderrh);
fclose($stderrh);
$errstr=null;
if(curl_errno($ch)){
    $errstr = curl_errno($ch).": ".curl_error($ch)." verbose: ".$stderr;
}
curl_close ($ch);
if(isset($errstr)){
    echo $errstr;
}

但这通常是一种过度杀伤力

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68064801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档