Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

php make SOAP Calls in a loop

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;
  }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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: 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.

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...