問題描述
在 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 本人提出了以下解決方案:
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
";
這篇關于PHP 中的 SoapClient 錯誤回退的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!