tags:

views:

217

answers:

4

I have a script that currently has a step where I trigger a voice broadcast after a customer signs up. It's a nusoap call to callfire.

The latency there is rather high, and it's added about 2 seconds to my sub-second sign up process. As a result, I have people hitting the sign up button more than once.

Is there a way to tell the app to NOT wait for the results and just move on?

It's possible to cheat by putting all of the nusoap code in a separate file, then open a socket to that file, but I'm looking for a cleaner way.

Or is there a way to fire off a function and not wait for the results? I don't think there is.

A: 

If you have some action which just has to be "soon" rather than "right away", then add it to a queue of some sort (e.g. a database table).

Next, have a cron job come along every minute or so and perform tasks that are in this queue.

Paul Dixon
A: 

As far as I know there isn't a way to directly fire off a function and move past it in the execution chain... but there are some cool / simple solutions:

  • As you mentioned, putting the code in a separate file and firing it off that way... although I'd just use a shell_exec command to run it and nohup it so it ran in the background
  • Create a queue as Paul mentioned
  • Look into something like gearman (http://www.danga.com/gearman/)... Digg wrote some nice PEAR libs for working with it. Gearman's probably a bit overkill, but it's too cool not to mention :)
Ian Selby
A: 

You might think about doing some Ajax request from the browser :

  • user signs in
  • he is redirected to a page (his account page, for instance)
  • on that page, there is an Ajax call to a PHP script on your server, that does the SOAP call

That's an idea that you'll often hear, I think... But it requires the user to hava Javascript enabled, and might not always work nice (what if the user leaves the page before the Ajax request is finished ? )

IMHO, the best (more secure, will always work, doesn't depend on the client, ...) way would really be with some request queue, like Paul suggested.
That's the solution I'd choose.

But, of course, it adds some delay between the user's signing in, and the time the request is sent... but is it that bad ?

Pascal MARTIN
+1  A: 

You can move the code to a cli script. Run the cli script from the web server PHP thread. The CLI process then forks, and the parent exits. The web thread can continue and the CLI child process can sign up the user.

In case of failure wih the SOAP call, I suggest you store the data somewhere and remove it or mark it as finished once is successfull. You can have a cron job routinely check to see if any calls failed, and retry them then notify someone (admin, user).

OIS