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.
Visitor Comments
-
hi,
i create a web service with asp.net ,save the wsdl in c:wampwww 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:wampwwwk.php on line 6
how do i solve my problem?
how do i do things that u say?
thanks
by azade on 01 Aug 2008 14:12 GMT
-
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.
by adcworks on 04 Aug 2008 23:11 GMT














