doukong5394 2012-12-11 16:33
浏览 93
已采纳

如何在PHP中使用NuSOAP处理超时?

I am using NuSOAP to consume a webservice for a payment gateway, however, the documentation for this gateway requires that:

  • If the doPayment() method takes more than 300 seconds, it should immediately execute the getStatus() method at least 3 times in order to try to get a successful response.

The thing is, I don't know how to handle that timeout with PHP and NuSOAP. Does NuSOAP returns any specific response when there's a timeout? how do I now it actually timed out?

Here is a piece of code for the NuSOAP call:

$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

Any input would be greatly appreciated. Thank you!

  • 写回答

1条回答 默认 最新

  • duangongqiong6958 2012-12-19 16:55
    关注

    I'm answering it myself for future reference. First of all you need to extend the timeout value for the nusoap_client class. Then just start a timer before the method you want to test and compare it to the time it took to end:

    // 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效