Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am getting following exception in my php page.

SoapFault exception: [HTTP] Error Fetching http headers

I read couple of article and found that default_socket_timeout needs configuration. so I set it as follow. default_socket_timeout = 480

I am still getting same error. Can someone help me out?

share|improve this question
add comment (requires an account with 50 reputation)

2 Answers

I have been getting "Error fetching http headers" for two reasons. One is that the server takes to long time to answer. The other is that the server does not support Keep-Alive connections (which my answer covers). PHP will always try to use a persistent connection to the web service (sending the "Connection: Keep-Alive" HTTP header). If the server always closes the connection and has not done so (PHP has not recived EOF), you can get "Error fetching http headers" when PHP tries to reuse the connection that is already closed on the server side.

Please note that this scenario will only happen if the same SoapClient object sends more than one request and with a high frequency. Sending "Connection: close" HTTP header along with the first request would have fixed this.

In PHP version 5.3.5 (currently delivered with Ubuntu) setting the HTTP header "Connection: Close" is not supported by SoapClient. One should be able to send in the HTTP header in a stream context (using the $option - key stream_context as argument to SoapClient), but SoapClient does not support changing the Connection header.

An other solution is to implement your own __doRequest(). On the link provided, a guy uses Curl to send the request. This will make your PHP application dependent on Curl. The implementation is also missing functionality like saving request/response headers.

A third solution is to just close the connection just after the response is received. This can be done by setting SoapClients attribute httpsocket to NULL in __doRequest(), __call() or __soapCall(). Example with __call():

class MySoapClient extends SoapClient {
    function __call ($function_name , $arguments) {
        $response = parent::__call ($function_name , $arguments);
        $this->httpsocket = NULL;
        return $response;
    }
}
share|improve this answer
add comment (requires an account with 50 reputation)
up vote 0 down vote accepted

One of my process within web service was taking long time to execute. Therefore I was getting soapfault exeception.

share|improve this answer
And you fix this? I'm trying increase timeout, but it doesn't help :(. Thanks – Dmitriy Sep 6 '11 at 17:54
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.