views:

605

answers:

1

I have a process I want to run in the background of a page. The process will take a while to run, lets say a few minutes.

I have it set up so that from the page I can click on a button to start the process off, wait a bit and then it will finish and I can have the page update notifying me that the process was run successfully. I'm doing this with prototype and php.

What I want to do is have status updates while the process is running. So it could update a the page letting me know how many records have been processed so far or update a status bar or something like that.

Is this possible? I'm just not a huge JS guru and I can do the basic functionality I've already described but was wondering if it was possible to extend it to do this little extra bit as I haven't had any luck googling or looking through the docs.

A: 

With just PHP you'll pretty much end up doing polling. You'll need to spawn your long-running process in the background, and for example write to a database of file what it's progress is.

The browser can then call a different php script every x seconds, which reports back with this status.

Polling sucks though, but that's what you're stuck with, with PHP.

Evert
So fork the process, and then have the process update a file/db... ok that could work. You say that with PHP that's what I'm stuck with, I mean i could write this particular module in python or perl or whatever, what would be some other options that wouldn't require polling? Just curious.
threendib
Actually.. IF you are running through CGI / mod_php or anything else.. don't fork! Just launch a new process altogether. (although technically that is also forking, but wanted to point out the distinction).
Evert