PHP soap extension error: Error Fetching http headers Some times you might come across the mysterious web service error in PHP saying: 'Error Fetching http headers'
What it means is that connection or the call itself to the web service took longer than expected. Extensions does not want to wait forever so decides to quit with error.
How to fix it?
- fix the service to run faster
- set higher limits
How to increase PHP soap timeout
To make PHP SoapClient timeout after ceriain amount of seconds at both connections and sopa calls you can do the following:
$old = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 5);
$params = array("trace" => true, "connection_timeout" => 5);
new SoapClient($wsdl, $params);
//do the call (both connect and call will be restricted)
ini_set('default_socket_timeout', $old);
This a kind of hack as you are changing the global socket timeout but it should not matter as there is no other thread/process that can be affected. If you succeed with the call no harm done, if you fail you can still change it back.
Point is, default soap client setting only sets limit for connection timout not the web service call (which might be very slow). If you need to allow longer or restrict shorter response times use that trick above.
Comments
Post new comment