Reputation: 298
We are implementing api with curl. We send xml request and get xml response. Some cases randomly we did not receive any response. When we co-ordinated with api provider they told there is no request hit on there server in case of blank response.
How we will know, its not hit on api provider server. Is there any header response ?
Upvotes: 0
Views: 715
Reputation: 5665
Some troubleshooting cURL options:
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($ch, CURLOPT_TIMEOUT,100);
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);
Get results
$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));
$responseHeader = substr($data,0,$skip);
$info = curl_getinfo($ch);
$requestHeader = $info['request_header'];
$info = var_export($info,true);
echo "<pre>$requestHeader \n\n $responseHeader\n\n $info \n $data";
Upvotes: 1
Reputation: 303
Add to your curl query:
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl will be more verbose
curl_getinfo($ch);
can also be helpfull
Upvotes: 0
Reputation: 1855
You need to add some code to handle response I don't know how your code looks like but it may be as simple as this
// add this line before curl_exec
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$status = curl_getinfo($curl);
// do this before closing curl connection
curl_close($curl);
and here is some more details about curl_getinfo http://php.net/manual/en/function.curl-getinfo.php
Upvotes: 0
Reputation: 5443
You can get curl error and errorno.Use this
var_dump(curl_errno($ch));
var_dump(curl_error($ch));
Upvotes: 1