几乎所有工作的 PHP 程序员都必须使用 CURL 发送原始 HTTP 请求,无论是信用卡支付处理、恶意屏幕抓取,还是介于两者之间。
几乎任何PHP程序员聚集的论坛都有大量的人can't get the cURL functions to do what they want .
当 cURL 不适合您时,您使用什么故障排除技术来找出它不工作的原因?您在 PHP 的 curl 实现中遇到过哪些奇怪的问题?如果有人在论坛上提出“HALP MY CURL IZ BROKEN”问题,您采取了哪些步骤来弄清楚为什么他们的请求不起作用?
最佳答案
我发现 CURLINFO_HEADER_OUT 选项非常有用。
<?php $curl = curl_init('http://www.php.net'); curl_setopt($curl, CURLOPT_HEADERFUNCTION, 'dbg_curl_data'); curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'dbg_curl_data'); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_exec($curl); echo '<fieldset><legend>request headers</legend> <pre>', htmlspecialchars(curl_getinfo($curl, CURLINFO_HEADER_OUT)), '</pre> </fieldset>'; echo '<fieldset><legend>response</legend> <pre>', htmlspecialchars(dbg_curl_data(null)), '</pre> </fieldset>'; function dbg_curl_data($curl, $data=null) { static $buffer = ''; if ( is_null($curl) ) { $r = $buffer; $buffer = ''; return $r; } else { $buffer .= $data; return strlen($data); } }
关于php - 您采取了哪些步骤来解决 PHP cURL 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/815910/