Page 1 of 1
How can I look at what's inside a resource handle?
Posted: Wed Sep 02, 2009 12:26 pm
by Mitch_H
Hello Forum,
I am having a sporadic problem with some cURL code inside a PHP script that calls a FedEx price estimation module on FedEx's website. After setting several options which are referenced by the $ch handle, I would like to actually see what is contained there before the curl-exec statement.
I have scoured the Internet to see if anyone can tell me how to dump a piece of memory that is referenced by a handle, but to no avail. I tried the following snippet, but it comes up empty;
Code: Select all
$fhandle = fopen("/home/vineyard/tmp/tests/mitchCurl.txt", "w");
copy($ch, $fhandle);
fclose($fhandle);
Can anybody help me see what I am sending FedEx as a request? I need to see the headers as well.
Re: How can I look at what's inside a resource handle?
Posted: Wed Sep 02, 2009 12:47 pm
by requinix
You can't peer into resources like that.
Besides packet sniffing, you can set the CURLOPT_HEADER to get the response headers in the output.
For the headers you're sending, your code and the CURLOPT settings you gave should reveal that. (What's your code?)
Re: How can I look at what's inside a resource handle?
Posted: Wed Sep 02, 2009 1:12 pm
by Mitch_H
Tasairis, thanks for the fast response.
I can't use packet sniffing because I am sending the requests to an https: destination, so the contents will be encrypted (I believe).
I can't use the CURLOPT_HEADER because the sporadic problem causes a 400 response code, that's why I want to know exactly what is being sent.
I have read that several of the cURL settings are defaults, and not being set by the PHP script. When my production Centos Linux server is receiving a 400 response while my test WAMP server is receiving a valid response for what appears to be the same inquiry, I want to compare the actual data streams being sent to FedEx to figure out what is actually different. Is there a cURL command that will show me the actual contents BEFORE sending. I tried $curlInput = curl_multi_getcontent($ch) before the curl_exec but nothing is returned. It only works after the curl_exec.
Being a mainframe programmer for 25+ years, it's hard for me to understand how a handle, which to me is a numbered pointer, can't be dumped. I would think that there was a memory address and length assigned to the handle, and this memory should be visable somehow, since the address would be owned by the PHP script executing.
Re: How can I look at what's inside a resource handle?
Posted: Wed Sep 02, 2009 2:45 pm
by requinix
What options and such are you giving to cURL? (Basically asking you to post code.)
Re: How can I look at what's inside a resource handle?
Posted: Wed Sep 02, 2009 3:00 pm
by Mitch_H
The actual FedEx script is rather large. It was written for Zen Cart. The fuction for setting the curl statements is;
Code: Select all
function _AccessFedex($data)
{
if (MODULE_SHIPPING_FEDEX_GROUND_SERVER == 'production') {
$this->server = 'gateway.fedex.com/GatewayDC';
} else {
$this->server = 'gatewaybeta.fedex.com/GatewayDC';
}
if (MODULE_SHIPPING_FEDEX_GROUND_CURL == "NONE") {
$ch = curl_init();
// added for proxy
if (MODULE_SHIPPING_FEDEX_GROUND_CURL_PROXY != 'NONE') {
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY, MODULE_SHIPPING_FEDEX_GROUND_CURL_PROXY);
}
// end proxy settings
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://' . $this->server);
if (MODULE_SHIPPING_FEDEX_GROUND_TIMEOUT != 'NONE') curl_setopt($ch, CURLOPT_TIMEOUT, MODULE_SHIPPING_FEDEX_GROUND_TIMEOUT);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Referer: " . STORE_NAME,
"Host: " . $this->server,
"Accept: image/gif,image/jpeg,image/pjpeg,text/plain,text/html,*/*",
"Pragma:",
"Content-Type:image/gif"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$reply = curl_exec($ch);
curl_close ($ch);
} else {
$this->command_line = MODULE_SHIPPING_FEDEX_GROUND_CURL . " " . (MODULE_SHIPPING_FEDEX_GROUND_TIMEOUT == 'NONE' ? '' : '-m ' . MODULE_SHIPPING_FEDEX_GROUND_TIMEOUT) . " -s -e '" . STORE_NAME . "' --url https://" . $this->server . " -H 'Host: " . $this->server . "' -H 'Accept: image/gif,image/jpeg,image/pjpeg,text/plain,text/html,*/*' -H 'Pragma:' -H 'Content-Type:image/gif' -d '" . $data . "' 'https://" . $this->server . "'";
exec($this->command_line, $this->reply);
$reply = $this->reply[0];
}
return $reply;
}
Re: How can I look at what's inside a resource handle?
Posted: Wed Sep 02, 2009 3:42 pm
by requinix
I see two problems: Host and Pragma (talking about the extra headers).
1. The Host is the name of the server but your $this->server is a path. You can do
Code: Select all
"Host: " . strtok($this->server, "/"),
2. Pragma needs a value. If you don't want to give one, don't provide a Pragma.