我正在使用NuSOAP为支付网关使用Web服务,但是,此网关的文档要求:
问题是,我不知道如何使用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
任何输入都将不胜感激。谢谢!
答案 0 :(得分: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