PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 异常无法连接到主机)
问题描述
使用此代码我发出肥皂请求
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)
) - 如果没有,请检查您遇到的错误类型
- 打印时间并检查 SOAP 服务器上的错误日志
- 一个 403 Forbidden 或类似服务器上的问题的错误点
- 无法连接错误指向网络问题(并非唯一,但这种情况的可能性更高)
- check if you can connect to the server in another way (for example
file_get_contents($soap_url)
) - if not, check what kind of error you are getting
- print the time and check the error logs on the SOAP server
- a 403 Forbidden or similar error points on a problem on the server
- a Could not connect error points to a network problem (not exclusively but chances are higher for that)
总而言之,有时错误"很难调试,因此您要么应该尝试使其可重现(这将指向问题),要么您需要记录和输出尽可能多的数据,以便您可以查看问题发生时的位置.
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 异常无法连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP SoapClient:SoapFault 异常无法连接到主机
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01