dongmaxi6763 2014-01-16 10:15
浏览 154

即使在捕获异常后,PHP SoapClient在脚本完成时会触发致命错误?

Consider the following script run for a URL that's known not to contain a valid WSDL:

<?php

echo "start
";

try {
   $test = new SoapClient ('http://www.example.com/');
} catch (Exception $e) {
   echo "Caught exception
";
}

echo "end
";

As expected, it logs out the following when run:

start 
Caught exception 
end

so the script did run to completion in spite failing to connect to a SOAP server. This is exactly what I was expecting. What I didn't expect was the following also getting logged to /var/log/php_error:

PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 'http://www.example.com/' in soapfail.php on line 6

if you have display_errors turned on, the result just looks plain bizarre.

start
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.example.com/' : Extra content at the end of the document
 in soapfail.php on line 6
Caught exception
end

It seems that in this case, PHP is emitting a fatal error even though the script didn't stop execution at that point. Obviously this is a hugely simplified and contrived example, but I discovered this behaviour in a live system that was doing SOAP requests against a server that had gone down. The fatal errors showing up in the log led us to believe that we were failing to handle an error properly, when in fact it seems that PHP is just emitting a fatal error notification when it shouldn't be.

Is there anything I can do about this behaviour other than turning off logging (which really isn't an option)?

UPDATE: The PHP version I'm using, for completeness, is:

PHP 5.4.6-1ubuntu1.5 (cli) (built: Dec 12 2013 04:39:44) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

I also tested this on my home machine with similar results.

PHP 5.5.5 (cli) (built: Oct 20 2013 23:15:05) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans

UPDATE 2:

I filed a bug report because this just doesn't seem correct to me. Report on php.net

  • 写回答

3条回答 默认 最新

  • doujie1917 2014-01-16 10:35
    关注

    You can try this code:

    <?php
    
        echo "start
    ";
    
        try {
           $test = new SoapClient ('http://www.example.com/', array('exceptions'=>true));
        } catch (Exception $e) {
           echo "Caught exception
    ";
        }
    
        echo "end
    ";
    
    ?>
    

    It will help you to catch exception

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler