How do I make an asynchronous call to a web service using the PHP SOAP Extension?
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:
- Use the exec functions to spawn another process, in the background, and monitor it through the database/file system or whatever.
- 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.
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.
Do it clientside rather than server side using an AJAX type call.
Try the method they gave me in my question: http://stackoverflow.com/questions/124462/asynchronous-php-calls
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