有时无法调用Web服务.
这个问题一直在发生.
可能是什么问题呢?
Error:
SoapFault exception: [HTTP] Could not connect to host in
0 [internal function]: SoapClient->__doRequest('<?xml version="...', http://.', '', 1, 0)
Run Code Online (Sandbox Code Playgroud)
uja*_*ava 28
问题解决了.问题是缓存
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
Run Code Online (Sandbox Code Playgroud)
Vol*_*enD 21
我正在添加我对完整性的评论,因为此处列出的解决方案对我没有帮助.在PHP 5.6上,SoapClient首次调用指定的WSDL URL SoapClient::SoapClient,在连接到它并接收结果后,它会尝试连接到结果中指定的WSDL:
<soap:address location="http://"/>
Run Code Online (Sandbox Code Playgroud)
Could not connect to host如果WSDL与您指定的WSDL不同SoapClient::SoapClient并且无法访问(我的情况是使用http://host.local/的 SoapUI ),则调用将失败并显示错误.
PHP 5.4中的行为是不同的,它总是使用WSDL SoapClient::SoapClient.
Rob*_*mos 13
主机要么停机要么响应很慢.如果响应缓慢,您可以尝试通过connection_timeout选项或通过default_socket_timeout设置增加超时,看看是否可以减少故障.
http://www.php.net/manual/en/soapclient.soapclient.php
http://www.php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout
您还可以包含错误处理,因为zanlok指出要重试几次.如果您有用户实际等待这些SOAP调用,那么您将需要将它们排队并在后台处理它们并在完成后通知用户.
小智 8
php.ini文件中有一个soap配置部分,它控制着wsdl访问缓存,可能显示为:
[soap]
; Enables or disables WSDL caching feature.
soap.wsdl_cache_enabled=1 ;
Sets the directory name where SOAP extension will put cache files.
soap.wsdl_cache_dir="/tmp"
; (time to live) Sets the number of second while cached file will be used ; instead of original one.
soap.wsdl_cache_ttl=86400
Run Code Online (Sandbox Code Playgroud)
如果启用了wsdl文件缓存,则在更改php代码中的wsdl URI时可能会导致此问题.在此示例中,您只需删除目录wsdl-下的文件启动即可/tmp.或者你只是设置soap.wsdl_cache_enabled=0;,soap.wsdl_cache_ttl=0;
PHP将在你每次访问页面时获取wsdl文件.
小智 7
这对我有用
$opts = array(
'ssl' => array('verify_peer' => false, 'verify_peer_name' => false)
);
if (!isset($this->soap_client)) {
$this->soap_client = new SoapClient($this->WSDL, array(
'soap_version' => $this->soap_version,
'location' => $this->URL,
'trace' => 1,
'exceptions' => 0,
'stream_context' => stream_context_create($opts)
));
Run Code Online (Sandbox Code Playgroud)
In our case, it was a Ciphers negotiation problem. We were getting this error randomly. We solved our problem by forcing a Cipher like this:
$soapClient = new SoapClient ('http://example.com/soap.asmx?wsdl',
array (
"stream_context" => stream_context_create (
array (
'ssl' => array (
'ciphers'=>'AES256-SHA'
)
)
)
)
);
Run Code Online (Sandbox Code Playgroud)
Looks like PHP wasn't negotiating the same Ciphers at each service call.
小智 6
一个错误配置的服务留下了与默认命名空间tempuri.org
这意味着到wsdl的连接将起作用,但是函数调用将失败。
堆栈跟踪:
SoapClient-> __doRequest(的'http://示例.com ...', ' http://tempuri.org ....',2,0)
要对此进行补救,您必须使用以下命令明确设置位置 __setLocation()
$this->soapClient = new \SoapClient(WS_URL);
$this->soapClient->__setLocation(WS_URL);
Run Code Online (Sandbox Code Playgroud)
小智 5
就我而言,它在连接到 wsdl 后起作用,使用该函数__setLocation()再次定义位置,因为调用失败并出现错误:
无法连接到主机
如果 WSDL 与 中指定的不同,就会发生这种情况SoapClient::SoapClient。
| 归档时间: |
|
| 查看次数: |
105568 次 |
| 最近记录: |