高效地重新加载数据/将数据从服务器推送到客户端 [英] Efficient reloading data / pushing data from server to client

查看:262
本文介绍了高效地重新加载数据/将数据从服务器推送到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们从网络服务器重新加载数据到前端时,我正在寻找最好的方式(即最有效,最常用,最常用的方法)。在最终应用程序中,我将有几个输出字段,其中数据必须写入,例如像这样:

I'm looking for the 'way to go' (i.e. the most efficient, most used, general accepted way) when it comes to the reloading of data from a web server to a front end. In the end application, I will have several output fields where data has to be written to, for example like this:

数据流将彼此不同在最终应用程序中。这些行必须从服务器重新加载新的,最新的数据。

The data streams will be different from each other in the end application. The lines will have to be reloaded with fresh, up to date data from the server.

我一直在想使用Ajax请求每秒更新一次,但是还有另外一种方法。 Ajax请求将导致大量数据流量。此外,当使用Facebook聊天时,您不必每隔一段时间,聊天几乎立即收到。但是当我使用Mozilla Firefox的开发工具时,我没有看到任何Ajax轮询请求。这使我想,如果有一个不同的方式来做这个。

I have been thinking of using Ajax requests to update like every second, but there has to be an other way to do this. Ajax requests will cause a lot data traffic. Also, when using the Facebook chat, you don't have to wait every second, chats are received almost instantly. Yet I don't see any Ajax polling requests being made when I use the developer tools of Mozilla Firefox. This made me think if there would be a different way to do this.

我看过Node.js,但它似乎是不可能与我的主机。

I've looked into Node.js, but it appears that isn't possible with my host.

我听说过有人在谈论Ajax Push,是我应该使用什么?如果是,您能给我一个基本的用法示例吗?

I have heard people talking about Ajax Push, is that what I should use? If so, can you give me a basic usage example?

如果没有,那么当有多个数据流时,必须在一秒钟内重新加载?

If not, what would then be the way to go when having multiple data streams that have to be reloaded within a second?

要求是速度 低数据流量。因此,我认为不会持续轮询服务器,因为这将产生巨大的开销。

Requirements are speed and low data traffic. It therefore wouldn't be an option to continuously poll the server, I think, because that would create an enormous overhead.

我不认为它是任何重要性,但我使用PHP5.3在后端和JavaScript的jQuery 1.9.1在前端。

推荐答案

这个问题已经被问了很多次,但是有点不同。以下是一些值得阅读的参考资料:

This question has been asked a number of times, but in a slightly different ways. Here are a few references that are worth a read:

  • What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?
  • Using comet with PHP?
  • Apache with Comet Support
  • Server Scalability - HTML 5 websockets vs Comet
  • How to implement event listening in PHP

总结:如果您正在使用Apache在Apache上构建解决方案,然后持有打开的持久连接或流)将非常快地用尽资源(非常低效)。因此,您最好使用托管解决方案(*免责声明 - 我工作的托管解决方案)。

In summary: if you are looking at building your solution using PHP on Apache then holding open persistent connections (HTTP long-polling or streaming) is going to use up resources very quickly (is highly inefficient). So, you would be better using a hosted solution (*disclaimer - I work for a hosted solution).

HTTP长轮询和HTTP流是解决方案,已被服务器发送事件和WebSockets取代。因此,在可能的情况下(Web客户端提供支持),您应该使用其中一个解决方案,然后再返回到基于HTTP的解决方案。一个好的实时web技术会自动处理这个。

HTTP-Long polling and HTTP Streaming are solutions which have been superseded by Server-Sent Events and WebSockets. So, where possible (where the web client provides support) you should use one of these solutions before falling back to an HTTP-based solution. A good realtime web technology will automatically handle this for you.

由于你的图表显示你正在订阅多个数据流,你应该考虑一个Publish/Subscribe 解决方案。再次,一个良好的实时web技术解决方案将为您提供这一点。

Since your diagram shows you are subscribing to multiple data streams you should also consider a Publish/Subscribe solution that naturally fits with this. Again, a good realtime web tech solution will provide you with this.

另见实时Web技术指南

这篇关于高效地重新加载数据/将数据从服务器推送到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆