views:

1428

answers:

6

How do I make an asynchronous call to a web service using the PHP SOAP Extension?

+2  A: 

My immediate answer should be: You can't.
PHP does not have threading abilities that can be used in "userland".

Now if you really want to do it, there are some ways you can go around it:

  1. Use the exec functions to spawn another process, in the background, and monitor it through the database/file system or whatever.
  2. Use the fork function to spawn another process and monitor it through the database/file system or whatever.

Setbacks of these 2 approaches is that you can make it asynchronous but if you want a callback then it's going to be very tricky and not at all trivial. Well, it ain't even gonna be a callback since you'll not be able to wait for it on the script that makes the async call. This means that you can only have some kind of monitoring scheme. I would suggest AJAX.

Gustavo Carreno
Or use curl multi: http://www.jaisenmathai.com/blog/2008/05/29/asynchronous-parallel-http-requests-using-php-multi_curl/
Tom
A: 

If you have the ability to do a command line php call in Linux, you could execute a pnctl_fork command and call the web service from the forked child process.

Devon
A: 

Do it clientside rather than server side using an AJAX type call.

Rich Bradshaw
What if the webservice is IP limited? Unless there's one client or all the clients are behind a single NAT router, it's not really possible.
Nouveau
What if you need the result on the web server?
Tom
A: 

Try the method they gave me in my question: http://stackoverflow.com/questions/124462/asynchronous-php-calls

UltimateBrent
A: 

I don't know why Gustavo was modded down as his is the right answer.

I use exec to run a shell script written in PHP that contacts google API. I start the script like this:

run.php param1=1 param2=2 &> ajax.txt

the last line of run is

echo 'finished'

then my ajax keeps polling 'ajax.txt' until it finds the process has finished.

Hacky, but simple (KISS)

monk.e.boy

monk.e.boy
+1  A: 

If you use curl, it has a set of 'multi' calls to allow parallel calls to multiple servers...