php在一个循环中进行SOAP调用 [英] php make SOAP Calls in a loop

查看:78
本文介绍了php在一个循环中进行SOAP调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php应用程序,该应用程序需要通过重复进行SOAP调用来获取用户数据(最多700个).不幸的是,这种将用于报告目的的目的似乎使得有必要进行重复调用.无论如何,我有一个For循环(最多可以重复700次),该循环调用一个函数,然后该函数又进行SOAP调用.但是我收到有关30秒后SOAP调用超时的错误.显然,在第一个返回调用函数之后,我需要等待下一个SOAP调用.那么如何做到这一点.这是一个代码片段:

I have a php application which needs to get user data by making repeated SOAP calls--up to 700. Unfortunately, the kind of reporting purposes that will serve seems to make it necessary to make the repeated calls. Anyway, I have a For loop (which could repeat for up to 700 times) which calls a function and the function, in turn, makes the SOAP call. But I am getting an error about the SOAP call timing out after 30 seconds. Obviously, I need to wait for the next SOAP calls after the first one returned to the calling function. So how to do this. Here is a code fragment:

//calling function
foreach($xml_apicheck->children() as $child)
{
  getprincipalinfoandemail($endusersconame);
 }
 //called function
 function getprincipalinfoandemail($loginid) {
  //making the SOAP calls and emailing//works for the first time called
   return true;
  }

推荐答案

要在不花费很长时间的情况下处理大量SOAP请求,最好的选择是派生PHP脚本并设置对多少个进程的限制你产生.每个fork将执行一个SOAP语句,等待它,然后最后结束.几年来,我编写了一个脚本来执行此操作,并撰写了有关其工作方式和实现方式的教程/文章.此特定示例说明如何使用NuSOAP库与索尼爱立信SMS网关(使用SOAP)一起使用.希望这能使您迅速理顺:

To get through a huge number of SOAP requests without taking a super long time, your best bet is to fork your PHP script and set a limit to how many processes you spawn. Each fork will execute a single SOAP statement, wait for it, then die at the end. I wrote a script to do this a few years and wrote a tutorial/post on how it works and how to implement it. This particular example is how to work with the Sony Ericsson SMS Gateway (which uses SOAP) using the NuSOAP library. Hopefully this will get you straightened out quickly:

http://jservedio.com/article/3

PS:这是几年前写的,所以我可能正在使用常规的MySQL库连接到数据库.如果必须连接到数据库,请确保使用的是PDO或mysqli-特别是如果要从GET或POST获取查询的任何输入.

PS: This was written several years ago so I may be using the regular MySQL library to connect to the database. If you have to connect to a database, make sure you are using PDO or mysqli - ESPECIALLY if you are getting any input for your queries from GET or POST.

响应您的评论,您不需要所有这些功能-您可以考虑创建SOAP请求标头和正文,然后使用cURL将其发送到需要的地方.这将等待响应(甚至在需要时将其定向到变量).

Edited: In response to your comment that you don't need all this capability - you may consider creating your SOAP Request Headers and Body then sending it out to where you need using cURL. This will wait for the response (and even direct it to a variable if you need).

这篇关于php在一个循环中进行SOAP调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆