2

i have a problem with SOAP, havent found a real answer.

try {
    $objResponse = $objSoapClient->$strMethod($objMethod->getSoapRequest());
}
catch (SoapFault $e) {  
    GlobalLogState::write("exception with code(".$e->getCode()."): \n".$e->getMessage());
}

This is my simple SOAP request in try catch block.

I'm getting a SoapFault Exception:

Error Fetching http headers

What is the reason of that?

Tigran Muradyan
  • 402
  • 1
  • 8
  • 24

2 Answers2

1

The configuration that has worked for me was defining at my php script the following parameters:

    ini_set('default_socket_timeout', 5000);
    $client = new \SoapClient($url,array(
    'trace' =>true,
    'connection_timeout' => 5000,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'keep_alive' => false,
));

Please, comment.

The most important parameter definition, as per my experience with this issue was ini_set('default_socket_timeout', 5000);

During my tests I have defined the default_socket_timeout to 5 seconds and the error 'Error Fetching http headers' was raised instantaneously.

I hope it helps you.

0

To fix this error, we can increase the either increase the socket timeout default_socket_time in php.ini or add the connection_timeout parameter in the parameter array passed to the constructor of the SoapClient.

These parameters are in seconds.

  1. In php.ini

    default_socket_timeout = 120

Alternatively, you can change from code

ini_set('default_socket_timeout', 120);

Note: The default socket timeout in php is 60 seconds.

  1. connection_timeout parameter in SoapClient constructor

$client = new SoapClient($wsdl, array('connection_timeout' => 120));

danronmoon
  • 3,814
  • 5
  • 34
  • 56
  • The error comes after like 5 seconds - I seriously doubt it has anything to do with timeout. and the problem was not there a few weeks ago, with the old webservice setup. What ever I changed in my C# soap service setup, had an impact, but what? I changed the response type from strongly typed to a XMLDocument. I even tried returning string. – Christian Jan 08 '20 at 12:39