使用此代码我发出肥皂请求
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 异常:[HTTP] 无法连接到主机
SoapFault exception: [HTTP] Could not connect to host
我的尝试
1) 我寻找解决方案,我读到这个问题可能是由 wsdl 缓存引起的,我在 php.ini
中禁用了它:
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
引发更少的异常
2) 我试图将 windows/system32/drivers/etc/hosts
中 dns 的分辨率添加到 windows 主机(它们在 windows 上):
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
引发更少的异常
3) 我也尝试禁用Windows 防火墙",
3) I also tried to disable "Windows Firewall",
引发更少的异常
4) 我也尝试增加 php.ini 中的 default_socket_timeout
4) I also tried to increase the default_socket_timeout in php.ini
default_socket_timeout = 90
什么都没有改变
问题
服务器soap似乎没有问题.从其他站点也可以正常使用.还有什么我可以做的吗?
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?
我的设置
PHP 5.6
阿帕奇 2.4
Windows Server 2012
Windows Server 2012
更新
经过多次测试,我认为问题出在网络上,soap server后面有一个反向代理,问题出现在代理上.
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) WSDL 变化很大吗?如果没有,打开 WSDL 缓存.您无需连接到服务器即可获取 WSDL 文件.
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.
你提到的输出真的是在 echo $e->getMessage();
中创建的吗?您可以在 catch()
块中添加一些调试代码,例如:
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)
)file_get_contents($soap_url)
)总而言之,有时错误"很难调试,因此您要么应该尝试使其可重现(这将指向问题),要么您需要记录和输出尽可能多的数据,以便您可以查看问题发生时的位置.
All 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.
这篇关于PHP SoapClient:SoapFault 异常无法连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!