using this code I make soap requests
$client = new SoapClient('http://example.com/soap/wsdl');
try {
$result = $client->myMethod();
} catch (Exception $e) {
echo $e->getMessage();
}
Sometimes (once out of ten), an exception is raised:
SoapFault exception: [HTTP] Could not connect to host
My attempts
1) I looked for solutions, and I read that this problem can be caused by wsdl cache, I disabled it in php.ini
:
soap.wsdl_cache_enabled = 0
soap.wsdl_cache_ttl = 0
raises fewer exceptions
2) I tried to add to the host of windows (they are on windows) the resolution of the dns in windows/system32/drivers/etc/hosts
:
160.XX.XXX.XX example.com
raises fewer exceptions
3) I also tried to disable "Windows Firewall",
raises fewer exceptions
4) I also tried to increase the default_socket_timeout in php.ini
default_socket_timeout = 90
nothing has changed
The question
The server soap does not seem to have problems.It is used without problems also from other sites. Is there anything else I can do?
My settings
PHP 5.6
Apache 2.4
Windows Server 2012
UPDATE
After many tests, I think that the problem is in the network, soap server is behind a reverse proxy, the problem appears in the proxy.
You need to improve your debugging efforts even further:
ad 1) Does the WSDL change a lot? If not, turn on WSDL caching. You don't need to connect to the server to fetch the WSDL file.
Is the output you mentioned really created in echo $e->getMessage();
? You could add some debugging code inside the catch()
block, for example:
file_get_contents($soap_url)
)for ($i = 0; $i <= 5; $i++) { /* ... */ sleep(1); continue; }
) to see if a second try would make it workAll in all, "sometimes errors" are hard to debug, so either you should try to make it reproducible (which will point at the problem), or you need to record and output as much data as possible so that you can see where the problem was at the time when it occurred.