2012-12-11 18 views
2

我使用的NuSOAP消費的支付網關Web服務,但是,這個網關的文件要求:如何在PHP中使用NuSOAP處理超時?

  • 如果doPayment()方法需要超過300秒,就應該立即執行的getStatus( )方法至少3次以嘗試獲得成功的響應。

事情是,我不知道如何處理PHP和NuSOAP超時。當有超時時,NuSOAP是否會返回任何特定的響應?我現在該如何超時?

這裏是該呼叫的NuSOAP一段代碼:

$client = new nusoap_client('http://webserviceurl?wsdl...' , 'wsdl'); 

$err = $client->getError(); 
if ($err) 
    die('Constructor error: ' . $err); 

$proxy = $client->getProxy(); 

$payTrans = $proxy->doPayment(array('someparams' => 'somevalues')); 

// if doPayment() timed out, then run the getStatus() method 

任何輸入將不勝感激。謝謝!

回答

5

我自己回答以備將來參考。首先你需要擴展nusoap_client類的超時值。然後,只需在要測試的方法之前啓動一個計時器,並將其與要花費的時間進行比較:

// Extending the timeout value to 300 seconds 
$client = new nusoap_client('http://webserviceurl?wsdl...' , 'wsdl' , false, false, false, false, 0, 300) 

$err = $client->getError(); 
if ($err) 
    die('Constructor error: ' . $err); 

$proxy = $client->getProxy(); 

$start = time(); // starting the timer 
$payTrans = $proxy->doPayment(array('someparams' => 'somevalues')); 
$timing = time() - $start; // calculating the transaction time 

if($timing > 90 && $timing < 310) 
    // It timed out: send an email, run another method, etc