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?
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With