Skip to content

How debug php curl sent traffic

1. If you only need sent headers

Add curl_setopt($ch, CURLINFO_HEADER_OUT, true); and than, after exec do this $headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT );

curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT );
echo $headerSent;

This prints headers which curl sent. You can obtain more information by curl_getinfo.

2. If you need more debuging info

You can use CURLOPT_VERBOSE option and catch info to stderror or redirect it to file. But be careful, CURLOPT_VERBOSE option don’t work together with CURLINFO_HEADER_OUT (I spent about hour with this bug). You can use only one from these two options (CURLOPT_VERBOSE or CURLINFO_HEADER_OUT).

curl_setopt($ch, CURLOPT_VERBOSE, true);
$fp = fopen(dirname(__FILE__) . '/curlLog.txt', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $fp);

But information from CURLOPT_VERBOSE are not so reach as these which you can obtain by last possibility.

3. If you need all information

If you need all information, including data sent! Than you can use cool freeware tool Fiddler. You can download it here. You don’t need to do additional setup on Windows 8+ for this purpose. You have to do one thing, use this curl option:

curl_setopt($ch, CURLOPT_PROXY, '');

That’s all. You can run your php script from console for example. And then under Raw tab in the Fiddler window, you have whole request sent. Including headers and content. It’s realy cool tool!

Post a Comment

Your email is never published nor shared. Required fields are marked *

šest − 5 =