AJAX Progress Bar - Polling, Comet?

心已入冬 提交于 2019-12-12 16:40:49

问题


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. :)


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/588284/ajax-progress-bar-polling-comet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!