AJAX 进度条 - 轮询、Comet?

发布于 2024-07-13 19:06:40 字数 343 浏览 11 评论 0原文

我想要一些关于如何实现以下内容的建议:

我想让我的用户了解通过 AJAX 在我的服务器上运行的任务的进度。 我的服务器运行一个 PHP 脚本,该脚本使用 popen 函数通过 shell 命令下载文件。 它定期回显/打印正在发生的事情。 我想使用 AJAX 捕获此输出并将其呈现给用户。

在另一个问题中我被告知我可能需要利用轮询或彗星? 我非常感谢任何关于如何以最简单和最有效的方式实现这一目标的帮助或指导。 希望我仍然可以使用 JQuery。

感谢大家花时间阅读本文。

PS,感谢 stackoverflow 社区,我能够走到这一步。 :)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一世旳自豪 2024-07-20 19:06:40

这听起来像是 Ajax 长轮询 的绝佳机会,这是一般 Comet 实现中使用的众多技术之一。 Stack Overflow 上还有一个问题,其中包含示例代码。

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.

寄与心 2024-07-20 19:06:40

Jim Puls 发布的链接是一个很好的起点。 许多用户在这些问题中提供了很多关于彗星投票和投票的重要信息。 PHP。 我见过的大多数地方都建议使用 python twins 来完成这项任务。

另外,这里还有一些链接:

响应式 AJAX使用 COMET 的应用程序

Jquery 中的进度条

以及另一篇 HTTP 流 AjAx 模式文章

我可能会选择最后提到的路线 gs,具体取决于进度条的“必要性”程度。 如果它只是一个帮助用户意识到处理时间比平常多一点的功能,那么用估计“欺骗”他们比实时轮询要容易得多。

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.

鸩远一方 2024-07-20 19:06:40

我只是使用常规轮询而不是彗星,因为这更像是一种黑客攻击。 为了使 UI 更加流畅,您可以作弊并更新进度条,而无需与服务器检查,只需计算完成任务所需的平均时间即可。 您可以通过轮询正确的状态来纠正错误。 如果你实施得好,每个人都会认为这是实时更新。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文