6

を使用して、いくつかの Web サービスを呼び出していますSoapClient。Web サービスがオフラインまたはダウンするたびに、エラーをユーザーに表示するのに役立つメカニズムを探しています。

ユーザーにエラーを表示する前に、しばらく(15秒)待つ必要があるためです。タイムアウトのために、このように追加connection_timeoutしています。SoapClient

$this->client = new SoapClient($clienturl,array('trace' => 1,
'exceptions'=> 1,
'connection_timeout'=> 15));   //$clienturl is webservice url

また、ページの上部セクションに、次の行を追加しました。

ini_set("default_socket_timeout", 15); // 15 seconds

特定のタイムアウト間隔の後、私はSOAP-ERRORこのように異なっています。

SOAP-ERROR: Parsing WSDL: Couldn't load from $clienturl

したがって、SOAP-ERROR「サーバーがダウンしています。しばらくしてからもう一度お試しください。またはタイムアウトエラーを処理する方法はありますか?

4

2 に答える 2

7

あなたはそれをtry/catchに入れることができます

try {
    $time_start = microtime(true);
    $this->client = new SoapClient($clienturl,array('trace' => 1,
        'exceptions'=> 1,
        'connection_timeout'=> 15
    ));
} catch (Exception $e) {
    $time_request = (microtime(true)-$time_start);
    if(ini_get('default_socket_timeout') < $time_request) {
        //Timeout error!
    } else {
        //other error
        //$error = $e->getMessage();
    }
} 
于 2012-12-14T08:42:37.170 に答える
1

これは、phpでsoapClient接続に使用しているものです

set_error_handler('error_handler');

function connectSoapClient($soap_client){
    while(true){
        if($soap_client['soap_url'] == ''){
            trigger_error("Soap url not found",E_USER_ERROR);
            sleep(60);
            continue;
        }
        try{
            $client = @new SoapClient($soap_client['soap_url'],array("trace" => 1,"exceptions" => true));
        }
        catch(Exception $e){
            trigger_error("Error occured while connection soap client<br />".$e->getMessage(),E_USER_ERROR);
            sleep(60);
            continue;
        }
        if($client){
            break;  
        }
    }
    return $client;
}


function error_handler($errno, $errstr, $errfile, $errline){
    if($errno == E_USER_ERROR){
        $error_time = date("d-m-Y H:i:s");
        $errstr .= "\n
            ############################### Error #########################################\n
            Error No: $errno 
            Error File: $errfile  
            Line No: $errline 
            Error Time : $error_time \n
            ##############################################################################
        ";
        mail($notify_to,$subject,$errstr);
    }
}
于 2012-12-14T08:53:17.870 に答える