PHP在用SOAP协议做接口的时候,经常会碰到如下问题,不是不成功,而是偶尔不成功,实在让人费解!
ERR: SOAP-ERROR: Parsing WSDL: Couldn‘t load from ‘http://www.xxxxx.com/member/member_sync.php?wsdl‘ : failed to load external entity "http://www.xxxxx.com/member/member_sync.php?wsdl"
查找日志发现:
NOTIC: [2] SoapClient::SoapClient(): I/O warning : failed to load external entity "http://www.xxxxx.com/member/member_sync.php?wsdl" /home/wwwroot/default/xxxxx.com/App/Modules/Admin/Action/OrderAction.class.php 第 112 行.
网上查找很多资料,有开启selinux、关闭soap缓存、开启openssl等等答案,但尝试过后都不尽人意,现终极解决办法:
只需把php的客户端SoapClient的wsdl模式修改为non-wsdl模式,即可解决!
wsdl模式:
<?php
$url = "http://xxxxx.org/member/member_sync.php?wsdl";
$client = new SoapClient ( $url );
$arr = array (
‘username‘ => ‘test123‘,
‘company‘ => ‘深圳市xxxxx科技有限公司‘,
‘password‘ => md5 ( md5 ( "test123" ) ),
‘encrypt_code‘ => ‘thisisencryptcode‘ ); //加密串,必须
$result = $client->common_func ( ‘sync_member‘, json_encode ( $arr ) );
var_dump ( $result );
?>
non-wsdl模式:
<?php
$client = new SoapClient(null,array(‘location‘=>‘http://www.zgzszj.com/member/member_sync.php‘,uri => ‘member_sync.php‘));
$arr = array (
‘username‘ => ‘test123‘,
‘company‘ => ‘深圳市xxxxx科技有限公司‘,
‘password‘ => md5 ( md5 ( "test123" ) ),
‘encrypt_code‘ => ‘thisisencryptcode‘ ); //加密串,必须
$result = $client->common_func ( ‘sync_member‘, json_encode ( $arr ) );
var_dump ( $result );
?>
webservice通过soap协议出现不能加载wsdl文件解决办法,布布扣,bubuko.com
webservice通过soap协议出现不能加载wsdl文件解决办法
原文:http://myitlife.blog.51cto.com/2289784/1529621