Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOWTO observe network traffic for curl debugging

Tags:

php

curl

I'm trying to make a curl call that also pass an image file along.
Obviously it's not working for me. However, I've got a test working that just use straight up html form.

How can I debug / print out the raw data that is being passed from curl?
Trying to compare the call with the form version to see what is different.

I've tried these:

curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, true);

print_r(curl_getinfo($curl));

But those seems to just return the response as opposed the raw request. (it's through a 3rd party so I have no access to the end point)

Thank you,
Tee

like image 869
teepusink Avatar asked Nov 14 '22 22:11

teepusink


1 Answers

curl the command line client has a --trace-ascii option for that. But that feature is not exposed in the PHP interface.

The _VERBOSE output might however still contain some information (if it's really a server error). You must redirect it into a separate file however before:

$fp = fopen("curl.log", "w");
curl_setopt($ch, CURLOPT_STDERR, $fp);

Failing that, I'm afraid the best option is to peek at the network traffic (using a separate tool, ad-hoc proxy maybe).

like image 63
mario Avatar answered Jan 06 '23 13:01

mario