gpt4 book ai didi

"new SoapClient()"的 PHP 不是那么致命的错误

转载 作者:行者123 更新时间:2023-12-04 05:25:57 27 4
gpt4 key购买 nike

我有这个片段运行:

foreach($config as $wsInfo){
try{
$soapClient = new SoapClient($wsInfo['url'],
array('encoding'=>'ISO-8859-1'));

// Some more code that I commented out.

}
catch(Exception $e){
echo "EXCEPTION: \n" . $e->getMessage();
// log it, etc.
}
}

当我运行该程序时,Web 服务 URL 会以身份验证错误响应我(在开发阶段这是可以的)。

我注意到的异常行为是,虽然我对此有所期待:
$ php scan.php -p=/ -c=config.yml
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"

它给了我这个:
$ php scan.php -p=/ -c=config.yml
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
in /home/me/project/DFPushSOAP.php on line 34
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
in /home/me/project/DFPushSOAP.php on line 34
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"

为什么“PHP fatal error ”没有杀死程序?为什么它会逃避 try/catch block ?

我怎样才能避免这种情况?

最佳答案

我遇到了同样的问题,并在 https://bugs.php.net/bug.php?id=47584 找到了解决方案.

首先你应该设置exceptions强制 SoapClient 抛出异常的选项:

    $soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1'
'exceptions' => true ));

在我的情况下,xdebug 强制产生 fatal error 而不是可捕获的异常。
因此,您应该尝试为 SoapClient 创建禁用 xdebug:
    if(function_exists('xdebug_disable')){ xdebug_disable(); };
$soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1'
'exceptions' => true ));
if(function_exists('xdebug_enable')){ xdebug_enable(); };

希望这对你有帮助^^

关于 "new SoapClient()"的 PHP 不是那么致命的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com