views:

772

answers:

3

Hi

I would like some advice on how to implement the following:

I would like to make my users aware of the progress of a task that is running on my server via AJAX. My server runs a PHP script that downloads a file via shell command using the popen function. It periodically echos/prints what is happening. I would like to capture this output using AJAX and present it to the user.

I was told in another question that I might need to make use of polling or comet? I would really appreciate any help or guidance on how to achieve this in the simplest and most efficient way. Hopefully, I can still make use of JQuery.

Thank you all for taking the time to read this.

P.S. I was able to get this far with thanks to the stackoverflow community. :)

+2  A: 

This sounds like a great opportunity for Ajax long polling, which is one of the myriad techniques used in general Comet implementations. There's another question on Stack Overflow with sample code.

Jim Puls
Thanks! Made use of that technique...well close enough that its working. :)
Abs
+1  A: 

I'd just use regular polling instead of comet, as this is more like a hack. To make the UI more fluid you could cheat and update your progress bar without checking with the server, just by calculating the average time it needs to do a task. You could correct the error by polling for the correct status. If you implement that well, everyone will think it's live updating.

Georg
+1  A: 

The link Jim Puls posted is a great place to start. Lots of users in that questions offer a lot of great information on Comet polling & PHP. Most places I've seen have recommended using python twisted to accomplish this task.

Also, here's a few links to:

Responsive AJAX applications with COMET

A Progress Bar in Jquery

And Another HTTP Streaming AjAx Pattern Article

I would probably go the route gs mentioned in the end depending on how "necessary" the progress bar is. If it's just a feature to help the user realize that it's taking a bit more time than usually to process, then "tricking" them with an estimation is a lot easier than the live polling.

Mesidin