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();
        $gearman->addServer('apps-1');
        $gearman->setTimeout(4000);
        $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/client.cc:154

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?

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();
    $gearman->addServer('apps-1');
    $gearman->setTimeout(4000);
    $result = $gearman->doNormal("function", "params");
    if (isset($errorHandler)) {
        set_error_handle($errorHandler);
    }