2013-02-04 01:18 阅读 81

php - try / catch gearman没有捕获超时警告

I'm using the php gearman client and I'm trying to catch/ignore any errors in the event the gearman server is offline:

    try {
        $gearman = new GearmanClient();
        $result = $gearman->doNormal("function", "params");
    } catch (Exception $e) {}

However, this is still outputting the following error message:

Warning: GearmanClient::doNormal(): _client_do(GEARMAN_TIMEOUT) occured during gearman_client_run_tasks() -> libgearman/

I know the error message is just a warning not a fatal error but I was hoping the try/catch would suppress it. Anyone know of a way around this? Putting an @ symbol just before $gearman->doNormal() does suppress the error however I don't know if thats the politically correct way of doing it.

Can someone help me out?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dpkiubcc265650 dpkiubcc265650 2013-02-04 01:31

    That is due to implementation. In PHP errors do not raise exceptions. If you want your program to be notified when a timeout occurs you have to manually inject into the errorhandler using set_error_handler.

        $errorHandler = set_error_handler(
             function($errorNumer, $errorString) { 
             //possibly handle error here
        $gearman = new GearmanClient();
        $result = $gearman->doNormal("function", "params");
        if (isset($errorHandler)) {
    点赞 评论 复制链接分享