Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapClient error fallback in 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:

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"

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?


Edit: I should say that I am running on PHP 5.2, if it makes any difference.

like image 462
Yuval Adam Avatar asked Jul 07 '11 08:07

Yuval Adam


1 Answers

This has already been discussed :

  • 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";
like image 111
Yuval Adam Avatar answered Oct 02 '22 00:10

Yuval Adam