7

I am doing a normal curl call to a webservice and I grab the return HTTP code through

$code = curl_getinfo ($ch, CURLINFO_HTTP_CODE);

It does return me $code as 200 - which is good. But logging the curl calls now from a week, there where few calls to the same webservice which didn't return anything! so basically I am getting $code as blank.

Can someone tell me what should be going wrong under those scenarios, and if can debug it more!?

Thanks, Tanmay

-----------------------Update-------------------------

Thanks everyone for the info. Yes I was also thinking the same, its not reaching the server. I will update my code with to get curl_error && curl_errno and will update you guys soon.

Thanks again.

---------------------- Update 2--------------------------------------------------------- I did update my code to return me the error no 7 - couldn't connect to host. I did logged all the curl calls, so basically around 90-98% of curl calls are executing good. But only 1-2% of curl calls are not able to find the host! Can anyone tell me what could be the reason? and How I can prevent it?

Thanks again, Tanmay

0

4 Answers 4

4

If the cURL HTTP code returned nothing (aka '0'), that means the cURL operation failed for some reason. It would be beneficial to capture the curl_error in your logs as well as it might give you more insight to was happened in those cases (if they happen again).

PHP: curl_error

Sign up to request clarification or add additional context in comments.

Comments

0

When you are logging it, check if it is blank, if it is, log more, using this function

http://www.php.net/manual/en/function.curl-getinfo.php

My guess would be that its not able to reach the server.

Comments

0

You can't retrieve a curl_getinfo from a request that failed. Check the result from curl_exec to determine whether an actual HTTP request has been performed.

A connect timeout or anything of the likes is a "failed request". In that case curl_exec returns FALSE (as stated in the curl_exec Manual).

Comments

0

My guess is that this is a situation where no HTTP headers were returned -- i.e. the request was unsuccessful. Perhaps the server's internet access was down, or for some other reason inaccessible.

If you look at the curl_getinfo docs, it suggests checking whether an error has occurred in the example:

if(!curl_errno($ch))
{
    $info = curl_getinfo($ch);

    echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.