PHP中的SoapClient错误回退 [英] SoapClient error fallback in PHP
问题描述
在PHP中,如果您尝试实例化新的 SoapClient
,并且无法访问WSDL(服务器停机或其他原因),则会引发PHP致命错误:
In PHP, if you try to instantiate a new SoapClient
, and the WSDL is not accessible (server down or whatever), a PHP fatal error is thrown:
严重错误:SOAP-ERROR:解析WSDL: 无法从加载 ' http://example.com/servlet/app/SomeService?wsdl ' :无法加载外部实体 " http://example.com/servlet/app/SomeService?wsdl " >
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com/servlet/app/SomeService?wsdl' : failed to load external entity "http://example.com/servlet/app/SomeService?wsdl"
据我所知,PHP中的致命错误是无法恢复的.
Fatal errors in PHP, as far as I know, are not recoverable.
有什么办法可以退缩吗?可以避免这种致命错误吗?
Is there any way to fallback from this? Can this fatal error somehow be avoided?
如果有什么不同,我应该说我正在PHP 5.2上运行.
I should say that I am running on PHP 5.2, if it makes any difference.
推荐答案
已对此进行了讨论:
- https://bugs.php.net/bug.php?id=47584
- http://www.php.net/manual/en/class.soapclient.php#104046
拉斯穆斯本人提出了以下解决方案:
Rasmus himself proposed the following solution:
<?php
try {
$x = @new SoapClient("non-existent.wsdl",array("exceptions" => 1));
} catch (SoapFault $E) {
echo $E->faultstring;
}
echo "ok\n";
这篇关于PHP中的SoapClient错误回退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!