PHP - Debugging Curl

PHP - Debugging Curl

You can enable the CURLOPT_VERBOSE option:

curl_setopt($curlhandle, CURLOPT_VERBOSE, true);

When CURLOPT_VERBOSE is set, output is written to STDERR or the file specified using CURLOPT_STDERR. The output is very informative.

You can also use tcpdump or wireshark to watch the network traffic.

How to debug curl in PHP?

Add the following code in the start and try again.

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL);

And if there is any parsing issue, then you will have to edit php.ini file and set this param

display_errors = on

How to debug a get request in php using curl

Add a few more option for troubleshooting purposes.

Check for an error response.

If no error, get the details:

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_FAILONERROR,true);
curl_setopt($ch, CURLOPT_ENCODING,"");

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);

$data = curl_exec($ch);
if (curl_errno($ch)){
$data .= 'Retreive Base Page Error: ' . curl_error($ch);
}
else {
$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE));
$head = substr($data,0,$skip);
$data = substr($data,$skip);
$info = curl_getinfo($ch);
$info = var_export($info,true);
}
echo $head;
echo $info;

How can I debug PHP cURL not triggering a request?

SELinux is preventing the httpd process from making a network connection.

setsebool -P httpd_can_network_connect 1

See the httpd_selinux(8) man page for details.

Steps for debugging php Curl on windows

Here is a list of steps for debugging Curl:

Check in phpinfo module that Curl IS enabled.

Verify extensions dir path is propperly set in php.ini and that extension=php_curl.dll is uncommented.

Check that Environment Variables are propperly set as per: http://php.net/manual/en/faq.installation.php#faq.installation.addtopath

Run deplister.exe ext\php_curl.dll to verify all dependencies are correctly satisfied.

If all of the above is working then check the output of CURLOPT_VERBOSE. As per @hp95 suggestion in the following thread: No Response getting from Curl Request to https server

If you are reaching a site that uses SSL check the following post: HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK

And fix it like these:

https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/

CURLOPT_VERBOSE not working

tl;dr

CURLOPT_STDERR must be set to something specific.

Setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+')); fixed my issue.


As it turns out curl_setopt($c, CURLOPT_VERBOSE, 1); is not printing the output to STDERR for some reason which I have not uncovered. I did not find the output in any of my PHP, Apache, nor Event Viewer logs.

After setting curl_setopt($c, CURLOPT_STDERR, fopen('/curl.txt', 'w+'));, I was able to see the output in the curl.txt file.

I am not sure if this is specific to Windows environments.

See what CURL sends from a PHP script

Thanks for all the answers! After all, they tell that It's not possible. I went down the road and got familiar with Wireshark. Not an easy task but definitely worth the effort.



Related Topics



Leave a reply



Submit