PHP Soap Multiple Concurrent Requests
March 19, 2013 4:12 PM   Subscribe

I need to send multiple concurrent soap requests to the same source, but concurrent requests aren't supported in PHP's SOAP implementation.

I can extend SoapClient to overwrite the _doRequest function to instead construct a curl handler to run as concurrent curl requests but I'd like to retain as much SOAP functionality as possible - specifically debugging and error catching/reporting.

I can run the requests via cURL but how do I turn them back into soap requests so that I only process the successful ones and can report on unsuccessful ones and use __getLastReponse() etc?

I found a library from DkLab that claimed to be able to do it but it didn't work - even the basic soap request didn't work, not even trying to do multiple concurrent requests.
posted by missmagenta to Computers & Internet (5 answers total)
 
Can you run multiple PHP instances simultaneously?

(Sympathies, I'm dealing with some pretty complex SOAP stuff in Perl right now, and if I weren't already bald I'd be tearing my hair out.)
posted by straw at 4:14 PM on March 19, 2013


Should mention, its running on Windows+IIS *shudder* and anything that requires the cooperation of the server admins is out of the question. It can take them 6 months to get around to setting up a new domain on the server.
posted by missmagenta at 4:17 PM on March 19, 2013


Would it be acceptable to make the requests directly from the browser? If so, some jQuery SOAP plugin should make the asynchronous requests very easy to make and manage.
posted by Monsieur Caution at 5:21 PM on March 19, 2013


Well, assuming you can serve it from the same origin as the web services. :)
posted by Monsieur Caution at 5:22 PM on March 19, 2013


You're very close, just not thinking in the right way :)

You don't want to modify SoapClient. That's going to make it hard to upgrade PHP in the future. Instead, write a worker.php in your app to handle the async requests, and call it asynchronously. The process would look like this:

1) Setup the request and store it in a shared location somewhere (file, memcached, DB, etc).
2) Perform an async curl request to your own server with a URL like worker.php?request_id=(something to identify the request in the shared area)
3) Repeat step (2) as many times as needed.
4) worker.php performs the normal SOAP request synchronously. Maybe it returns the result in a shared location. Maybe it returns it as serialize JSON over the HTTP request. Your choice.
5) In your master process, wait for all the async requests to complete.
6) Continue processing.

WP does something similar to handle cron jobs without bogging down the client user.

Make sure your worker.php only handles requests from approved hosts (ie: localhost), or authenticates with a shared secret, or uses a unique enough request ID. Just something to make sure external clients can't call it.

To your Windows admins it just looks like more HTTP requests.
posted by sbutler at 8:07 PM on March 19, 2013


« Older Playing Hookey, the Classy Way   |   How Do I Learn to Stop Worrying and Love Art... Newer »
This thread is closed to new comments.