PHP SoapClient Could Not Connect to Host
The Could Not Connect to Host error message when using PHP SoapClient can be a tricky sucker to trace the root of. There are varying responses across the internets to what may cause this problem such as firewalls and proxies.
But there is one other thing you can check. Look through the WSDL for the soap:address locations. You may find that a server name is given that the machine running your code does not have access to.
Take a look at the example below;
<service name="SomeService"> <port binding="tns:WebServiceBinding" name="WebServicePort"> <soap:address location="http://appserver3:8080/webservices/WebServiceEndPoint"/> </port> </service>
I experienced the issue when deploying my code from my dev machine to a live server. I couldn’t understand why my dev machine was fine calling the web services and the live server was not.
That’s because I had forgotten that I had provided access to my dev machine in the early days of coding to the appserver3 server name by virtue of a hosts file entry. Looking in my hosts file revealed
123.123.123.123 appserver3
And this is what was missing on the live server.
So if you get this error and you just can’t figure it out, take a wander through the WSDL for location URLs that may not be accessible to the server running your code. If you have a server name rather than an IP as in the example above, then add a hosts file mapping to the IP and you’re away.
| Print article | This entry was posted by admin on April 17, 2008 at 10:24 pm, and is filed under PHP. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
hi,
i create a web service with asp.net ,save the wsdl in c:\wamp\www as Service.wsdl
the location in wsdl is
‘http://localhost:54749/EBankServices/Service.asmx’
and use this code :
try {
$client = new SoapClient("Service.wsdl");
$result = $client->HelloWorld(‘azade’);
} catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
and the error:
Fatal error: SOAP Fault: (faultcode: HTTP, faultstring: Could not connect to host) in C:\wamp\www\k.php on line 6
how do i solve my problem?
how do i do things that u say?
thanks
about 1 year ago
Are you sure that all URLs inside the WSDL are available from your local machine when running the code?
You can try pinging each URL or putting the URL into a web browser, just to check that it exists.
So for example, is the URL:
http://localhost:54749/EBankServices/Service.asmx
Available to ping or in a web browser? The error usually means a URL in the WDSL is not reachable.
about 1 year ago
Exactly what I needed. Thanks.
about 1 year ago
If you are using SOAP over HTTPS (SSL) also check the following:
php -i | grep ssl
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
If it doesn’t say SSL in any of these then check for the SSL extension – it will not be loaded.
This will also cause the "Could not connect to host" issue.
This error is not very informative – while true that it cannot connect to host it could at least say "Cannot use SSL".
about 1 year ago
I had this problem making SOAP calls that required client certificates. I had forgotten to set the correct permissions on the cert to allow apache read access to it.