Friday 15 June 2012

soap - Check if SoapClient exists -


I'm struggling to detect errors in PHP ...

I have a simple function SoapClient related parts to get pieces of data from one of my servers that use:

  $ options = array ('uri' = & gt; 'https: //www.php-web-host.com ',' location '= & gt;' https: //www.php-web-host.com/API/Country.php ',' trace '= & gt; 1 ); $ Client = new SOAP client (zero, $ option); $ Countrycode = strollover ($ client- & gt; GetCountryCode ($ _ SERVER ["REMOTE_ADDR"]));   

The problem is that I am currently running that if I have not installed SOAP on the server running this code, then I get a 500 server error (I do not check But I think that the actual PHP problem is a serious exception?)

I have tried to wrap up in a try / catch block, but obviously it does not throw exceptions. I have also tried set_error_handler, but I can not "hold" this error.

Because of this I need to catch it (just to oppose installing SOAP) is that it is widely distributed for its code, so to connect me in any way Should be able to check soap before ...

Any help is greatly appreciated ...

John

OK, so I managed to solve my problem using the periklis example Area.

This example uses register_shutdown_function to say that when the page ends (due to or due to an error).

  register_shutdown_function ('shutdownFunction'); Function shutdown function () {$ error = error_get_last (); // Check that this error was related to my code, if not, then ignore it (($ error ['type'] == 1) & amp; amp; (strstr (strtolower ($ error ['message' ]), 'Soapclient'))) {Print "& lt; h1 style = \" color: red; \ "& Gt; Error! & Lt; / h1 & gt; Your server SOAP is not installed. SOAP is required for this function"; Go out(); }}   

It seems to work for me ... happiness!

No comments:

Post a Comment