检查SoapClient是否存在

检查SoapClient是否存在,soap,exception-handling,error-handling,try-catch,fatal-error,Soap,Exception Handling,Error Handling,Try Catch,Fatal Error,我正在与PHP中的错误检测作斗争 我有一个简单的函数,它使用SoapClient从我的另一台服务器获取数据。有关部分包括: $options = array( 'uri' => 'https://www.php-web-host.com', 'location' => 'https://www.php-web-host.com/API/Country.php', 'trace' => 1); $client = new SoapClient(NULL, $options);

我正在与PHP中的错误检测作斗争

我有一个简单的函数,它使用SoapClient从我的另一台服务器获取数据。有关部分包括:

$options = array(
'uri' => 'https://www.php-web-host.com',
'location' => 'https://www.php-web-host.com/API/Country.php',
'trace' => 1);

$client = new SoapClient(NULL, $options);
$CountryCode = strtolower($client->GetCountryCode($_SERVER["REMOTE_ADDR"]));
我现在遇到的问题是,如果我正在运行此代码的服务器上没有安装SOAP,那么我会得到一个500服务器错误(我没有检查,但我猜实际的PHP问题是致命的异常?)

我已经尝试将上述内容包装在try/catch块中,但显然它不会引发异常。我也尝试过设置错误处理程序等,但我无法“捕获”这个错误

我需要捕获它的原因(而不仅仅是安装SOAP)是因为它的代码将被广泛分发,所以我需要能够在连接之前以某种方式检查SOAP

非常感谢您的帮助


John

好的,所以我通过在上使用periklis示例来解决我的问题

该示例使用register\u shutdown\u函数,该函数在页面终止(正确终止或由于错误终止)时调用

register_shutdown_函数(“shutdown函数”);
函数关闭函数()
{
$error=error_get_last();
//检查此错误是否与我的代码有关,如果不是,请忽略它
if($error['type']==1)和&(strstrstr(strtolower($error['message']),'soapclient'))
{
打印“错误!您的服务器似乎没有安装SOAP。此功能需要SOAP”;
退出();
} 
}
这似乎对我有用。。。幸福

register_shutdown_function('shutdownFunction');

function shutdownFunction()
{

    $error = error_get_last();

    // check if this error was related to my code, if not, ignore it
if ( ($error['type'] == 1) && (strstr(strtolower($error['message']), 'soapclient') ) )
{

            print "<h1 style=\"color:red;\">ERROR!</h1>Your server does not appear to have SOAP installed. SOAP is required for this functionaliy";
    exit();
    } 

}