【发布时间】:2016-02-17 10:22:00
【问题描述】:
在我的 PHP Web 应用程序中处理“HTTP 500 内部服务器错误”时遇到问题。
我的网络应用程序正在循环访问多个外部网络服务,如果其中任何一个出现错误,我的脚本将终止而不执行其他 URL。
以下是我正在尝试处理的代码 sn-p,我们将不胜感激。
如果有人想了解更多信息,请告诉我。
$arrURLs = array('https://example1.com/abc1', 'https://example1.com/pqr2', 'https://example2.com/abc1', 'https://example2.com/pqr2');
$arrResponse = array();
foreach( $arrURLs as $strURL ) {
$soap_options = array('soap_version' => SOAP_1_1,
'debug'=>1,
'trace'=>1,
'exceptions'=>TRUE,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=> 500,
'stream_context' => stream_context_create(array('ssl' => array('verify_peer'=> false,'verify_peer_name'=>false,) ) ) );
try{
$client = new SoapClient( $strURL . '?wsdl', $soap_options );
$client -> __setLocation( $strURL );
$response = $client->method1();
array_push( $arrResponse, $response );
} catch(\Exception $e) {
$strError = 'Exception while connecting to URL: ' . $strURL . 'Error Message: ' . $e->getMessage();
echo $strError;
}
}
// parse $arrResponse after getting from all web services;
谢谢。
【问题讨论】:
-
为什么不捕获异常并重试请求?
-
“500”是脚本死机造成的。脚本死后无法继续。首先,您需要防止它死亡。检查错误日志以了解其终止的特定原因。
-
我可以澄清一下吗?是您的服务器给出 500 还是您正在访问的其他服务器给出了 500 错误?
-
@JimWright:我正试图抓住它,但捕获打击没有被执行。 RiggsFolly:其他服务器。 deceze:他们有什么方法可以防止脚本死亡,因为我想为给定数组中的所有 URL 执行脚本。
-
远程 API 中的错误应触发 SoapClient 中的异常。如果您无法捕获异常,您确定代码中没有发生错误吗?你有任何错误的示例堆栈跟踪吗?
标签: php web-services error-handling http-error httpexception