10

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395

2 Answers2

13

This has already been discussed :

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";
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
0

See this topic How do I catch a PHP Fatal Error

Basically you cant recover from a fatal error but you can provide a better experience to the user when registering a shutdown function

register_shutdown_function('handleShutdown');
function handleShutdown(){
    $error = error_get_last();
    if($error !== NULL){
        echo "Sorry for the inconvenience, an error just occurred.";
    }
}
Community
  • 1
  • 1
Andris
  • 27,649
  • 4
  • 34
  • 38