簡體   English   中英

如何顯示 PHP-cURL 錯誤?

[英]How do I display PHP-cURL errors?

頁面無法加載的原因可能是什么? 我目前正在向我的機器人發送請求,該請求會向我發送回復,但不知何故,如果機器人在線並正常工作,則頁面不會加載。 有沒有辦法得到錯誤? 我有一個 cPanel 並且 display_errors 是1 還有其他想法嗎?

這是我的要求之一:

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;
}

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

$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 獲得更多信息

$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;
}

但這通常有點矯枉過正

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM