Reputation: 3681
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?
Upvotes: 16
Views: 50188
Reputation: 906
I had the same issue and tried the following by disabling keep_alive
.
$api_proxy = new SoapClient($api_url, array('trace' => true, 'keep_alive' => false));
However, that didn't work for me. What worked worked for me was disabling the SOAP cache. It appears to have been caching the wrong requests and after disabling I actually noticed my requests were executing faster.
On a linux server you can find this in your /etc/php.ini
file.
Look for soap.wsdl_cache_enabled=1
and change it to soap.wsdl_cache_enabled=0
.
Don't forget to reload apache.
service httpd reload
Upvotes: 0
Reputation: 4796
I have been getting Error fetching http headers
for two reasons:
Keep-Alive
connections (which my answer covers).PHP will always try to use a persistent connection to the web service by sending the Connection: Keep-Alive
HTTP header. If the server always closes the connection and has not done so (PHP has not received EOF
), you can get Error fetching http headers
when PHP tries to reuse the connection that is already closed on the server side.
Note: 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 (Update: This bug was solved in PHP version 5.3.11).
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;
}
}
Upvotes: 30
Reputation: 3681
One of my process within web service was taking long time to execute. Therefore I was getting soapfault exeception.
Upvotes: -13