PHP 中的 SoapClient 错误回退

SoapClient error fallback in PHP(PHP 中的 SoapClient 错误回退)
本文介绍了PHP 中的 SoapClient 错误回退的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 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 错误回退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Uploading Image from android to PHP server(将图像从android上传到PHP服务器)
Sending file together with form data via ajax post(通过ajax post将文件与表单数据一起发送)
Laravel - validate file size when PHP max upload size limit is exceeded(Laravel - 超过 PHP 最大上传大小限制时验证文件大小)
How to upload file through Jquery/AJAX(如何通过 Jquery/AJAX 上传文件)
PHP: move_uploaded_file() failed to open stream: No such file or directory(PHP:move_uploaded_file() 无法打开流:没有那个文件或目录)
Creating a file progress bar in PHP(在 PHP 中创建文件进度条)