PHP SoapClient:SoapFault 异常无法连接到主机

PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 异常无法连接到主机)
本文介绍了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 异常无法连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

      本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)