Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapFault exception: Could not connect to host

Tags:

php

soap

Sometimes fail to call the web service.

This problem happens all the time.

What could be the problem?

Error:
    SoapFault exception: [HTTP] Could not connect to host in 
    0 [internal function]: SoapClient->__doRequest('<?xml version="...', http://.', '', 1, 0)
like image 641
ujava Avatar asked Nov 30 '10 21:11

ujava


3 Answers

The problem was solved.The problem is the cache

ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
like image 79
ujava Avatar answered Nov 01 '22 15:11

ujava


I am adding my comment for completeness, as the solutions listed here did not help me. On PHP 5.6, SoapClient makes the first call to the specified WSDL URL in SoapClient::SoapClient and after connecting to it and receiving the result, it tries to connect to the WSDL specified in the result in:

<soap:address location="http://"/>

And the call fails with error Could not connect to host if the WSDL is different than the one you specified in SoapClient::SoapClient and is unreachable (my case was SoapUI using http://host.local/).

The behaviour in PHP 5.4 is different and it always uses the WSDL in SoapClient::SoapClient.

like image 40
VolenD Avatar answered Nov 01 '22 14:11

VolenD


The host is either down or very slow to respond. If it's slow to respond, you can try increasing the timeout via the connection_timeout option or via the default_socket_timeout setting and see if that reduces the failures.

http://www.php.net/manual/en/soapclient.soapclient.php

http://www.php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout

You can also include error handling as zanlok pointed out to retry a few times. If you have users actually waiting on these SOAP calls then you'll want to queue them up and process them in the background and notify the user when they're finished.

like image 17
Rob Olmos Avatar answered Nov 01 '22 15:11

Rob Olmos