使用SoapClient中遇到Fatal error,错误类似
1 2 3 4 5 6 |
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/users/test_script/411.php:30 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://client.w...', 'http://tempuri....', 1, 0) #1 /home/users/test_script/411.php(30): SoapClient->__call('QueryJs...', Array) #2 {main} thrown in /home/users/test_script/411.php on line 30 |
根据stackoverflow提供的解决思路,通过在客户端脚本中添加
1 2 |
ini_set('soap.wsdl_cache_enabled',0); ini_set('soap.wsdl_cache_ttl',0); |
或者直接修改php.ini中有关soap的配置
1 2 3 4 5 6 7 8 9 |
[soap] ; Enables or disables WSDL caching feature. ;soap.wsdl_cache_enabled=1 soap.wsdl_cache_enabled= 0 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 soap.wsdl_cache_ttl= 0 |
这样的设置保证每次请求soap时不会读取cache的内容。
但是,问题依旧存在,囧。那就使用try/catch来捕获execption吧。
1 2 3 4 5 6 |
try{ $res = $client->__call('LineStopQueryJson',array('Parameters' => $params)); }catch(SoapFault $e){ print_r($client); //或者其他错误处理方式 } |
Done!
3条评论
我怀疑好多追着喷你的马甲就是觉醒的“五毛”
我怀疑好多追着喷你的马甲就是觉醒的“五毛”
我怀疑好多追着喷你的马甲就是觉醒的“五毛”