문제

사용자가 SOAPClient의 URL을 지정할 수있는 웹 앱을 작성하고 있습니다. 사용자가 양식을 제출할 때 PHP가 클라이언트에 연결할 수 있는지 확인하고 싶었습니다. 나는 catch 또는 set_error_handler (또는 둘의 일부 조합)를 통해 이것을 할 수 있습니다. 그러나 치명적인 오류는 불가능한 것 같습니다. 비누를 가져 오는 URL을 테스트 할 수있는 방법이 있습니까?

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com/wibble'

URL이 존재하지 않으므로 오류를 표시하기를 원하지만이를 잡을 수 있기를 원합니다.

그렇지 않으면 URL을 직접 다운로드하고 검증하려고 시도 할 수 있다고 생각하지만 Soapclient에서 수행 할 수 있다고 생각했을 것입니다.

이것이 치명적인 오류 여야합니까?

편집하다

Rogeriopvl의 답변을 읽은 후에 나는 Soapclient 생성자에 대한 '예외'옵션을 시도했으며 (절망적으로) 사용하여 사용하여 사용 된 것으로 말해야한다고 확신합니다.

도움이 되었습니까?

해결책

Are you using xdebug? According to this PHP bug report and discussion, the issue has been fixed at least since PHP 5.1, but this xdebug bug messes with 'fatal error to exception conversions' in a way that the exception is not generated and the fatal error 'leaks through'.

I can reproduce this locally, with xdebug enabled:

try {
  $soapClient = new SoapClient('http://www.example.com');
}
catch(Exception $e) {
  $exceptionMessage = t($e->getMessage());
  print_r($exceptionMessage);
}

This gives me the fatal error you described, without even entering the catch clause:

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.example.com'

It works if I disable xdebug right before the call:

xdebug_disable();
try {
  $soapClient = new SoapClient('http://www.example.com');
}
catch(Exception $e) {
  $exceptionMessage = t($e->getMessage());
  print_r($exceptionMessage);
}

This triggers the exception as expected, and I get a proper SoapFault Object in the catch clause with a message of:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.example.com'

So basically exceptions work as advertised. If they don't work in your case, you might encounter the xdebug bug, or maybe a similar issue with another 3rd party component.

다른 팁

Quoting SoapClient documentation:

The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault.

So you should try something like:

$client = new SoapClient("some.wsdl", array('exceptions' => TRUE));

This way will throw SoapFault exceptions allowing you to catch them.

See: http://bugs.xdebug.org/view.php?id=249

Possible solution:

Index: trunk/www/sites/all/libraries/classes/defaqtoSoapClient.class.php
===================================================================
--- classes/defaqtoSoapClient.class.php
+++ classes/defaqtoSoapClient.class.php
@@ -31,10 +31,23 @@

     try {
+        // xdebug and soap exception handling interfere with each other here 
+        // so disable xdebug if it is on - just for this call
+        if (function_exists('xdebug_disable')) {
+            xdebug_disable();
+        }
       //Create the SoapClient instance
       parent::__construct($wsdl, $options);
     }
     catch(Exception $parent_class_construct_exception) {
+        if (function_exists('xdebug_enable')) {
+            xdebug_enable();
+        }
       // Throw an exception an say that the SOAP client initialisation is failed
       throw $parent_class_construct_exception;
+    } 
+    if (function_exists('xdebug_enable')) {
+        xdebug_enable();
     }
   }

you could try and do a curl or fsockopen request to check the URL is valid.

For your information, i'm using SoapClient with PHPUnit to test remote WebServices and got the same problem!

  • when using an old PHPUnit version (3.3.x) as third party, phpunit crash
  • when using current version of PHPUnit (3.4.6) as third party, phpunit display "RuntimeException".

Here is my first test method :

public function testUnavailableURL() {
    $client = new SoapClient("http://wrong.URI");
}

Here is PHPUnit first result :

There was 1 error:

1) MyTestCase::testUnavailableURL
RuntimeException: 


FAILURES!

Here is my second test method :

public function testUnavailableURL() {
        try {
          $client = @new SoapClient("http://wrong.URI");
        } catch (SoapFault $fault) {
          print "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})";
        }
}

Here is PHPUnit second test result :

PHPUnit 3.4.6 by Sebastian Bergmann.

.SOAP Fault: (faultcode: WSDL, faultstring: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://wrong.URI' : failed to load external entity "http://wrong.URI"
)...

Time: 3 seconds, Memory: 4.25Mb

OK

NB: i found a phpunit ticket on this subject : ticket 417

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top