PHP SoapClient:SoapFault异常无法连接到主机 [英] PHP SoapClient: SoapFault exception Could not connect to host

查看:443
本文介绍了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

没有任何改变

问题

服务器肥皂似乎没有问题,其他站点也没有问题地使用它.我还能做些什么吗?

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

PHP 5.6

Apache 2.4

Apache 2.4

Windows Server 2012

Windows Server 2012

更新

经过多次测试,我认为问题出在网络上,soap服务器位于反向代理后面,问题出现在代理中.

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禁止访问或类似错误点
    • 无法连接错误点指向网络问题(不是排他性的,但机会更大)
    • 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异常无法连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆