tags:

views:

652

answers:

3

When using the PHP curl functions, is there anyway to see the exact raw headers that curl is sending to the server?

+5  A: 

You can use curl_getinfo:

$headers = curl_getinfo($c, CURLINFO_HEADER_OUT);
Greg
No, that's not how it works and that code doesn't work
Daniel Stenberg
Uuuh, I've not kept up. That _is_ how it works... sorry!
Daniel Stenberg
+2  A: 

be sure to set the CURLINFO_HEADER_OUT option before making the curl_getinfo call

curl_setopt($c, CURLINFO_HEADER_OUT, true);

Janek
That's not working code
Daniel Stenberg
Please point out what's wrong with it.
Janek
@JanekIt should be read as follows: curl_setopt($c, CURLOPT_HEADER, true);
pcdinh
Janek is correct, CURLINFO_HEADER_OUT is the option to set if you want to view the header using curl_getinfo() it is documented here http://php.net/manual/en/function.curl-setopt.php
gawpertron
+1  A: 

AFAIK, the PHP/CURL binding still lacks proper support for CURLOPT_DEBUGFUNCTION which is a callback from libcurl that can provide all those details.

That's the primary reason why I recommend people to work out HTTP scripting things with the curl command line tool and its --trace-ascii option FIRST, then translate that into a PHP function.

Daniel Stenberg
It looks like you're right, I poked around the latest stable PHP source a bit, and it looks like they **use** CURLOPT_DEBUGFUNCTION to implement their CURLINFO_HEADER_OUT options, but they don't expose a fully featured CURLOPT_DEBUGFUNCTION of their own. Side note: I remember your emails from the php curl mailing list. I'm amazed you still have the patience to do any kind of PHP related libcurl support :)
Alan Storm