AJAX/反向AJAX:轮询还是推送? [英] AJAX/Reverse AJAX: Polling or Push?

查看:124
本文介绍了AJAX/反向AJAX:轮询还是推送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我正在使用Javascript和PHP制作实时应用程序,所以对AJAX进行了大量研究.它需要能够在不刷新页面的情况下进行实时更新.

Been studying a ton on AJAX because I'm making a real-time application out of Javascript and PHP. It needs to be able to update without refreshing the page and in real-time.

我尝试使用setInterval()轮询服务器,但是为了快速起见,我不得不每秒都进行一次操作.它似乎正在使用大量带宽.但是它确实可以工作,我和我的托管服务提供商有一个无限带宽"的计划.不过,似乎网站上的压力很大,所以我想使用Push技术.

I tried polling the server with setInterval() but for it to be quick I had to have it every second. It seems to be using a ton of bandwidth though. It does work however and I have a plan with my hosting provider for 'unlimited bandwidth'. It seems like a lot of stress on the site though so I wanted to use a Push technology.

学习如何设置Push极为困难.从我设法弄清的结果来看,您必须托管某种类型的推送服务器或彗星服务器.我也研究了websockets,但您也必须自己托管它.如果我没有服务器计算机,并且托管服务提供商的网站上没有关于此的任何文档,我将不知道该怎么做.

Learning how to setup Push was extremely difficult. From what I managed to figure out, you have to host some type of push server or comet server. I also looked into websockets, but there too you had to host it yourself. I don't understand how to do that when I do not own a server computer and there is no documentation on my hosting providers website about this.

特定的托管服务提供商是否为您托管推送服务器?有没有一种方法可以在不必托管服务器的情况下获取服务器?与轮询相比,这似乎是一个更好的选择,但与此同时,它却极度令人困惑.

Do specific hosting providers host push server for you? Is there a way to get a server without having to host it? It seems like a much better choice over polling, but at the same time it seems extremely confusing.

推荐答案

特定的托管服务提供商是否为您托管推送服务器?有没有一种方法可以在不必托管服务器的情况下获取服务器?与轮询相比,这似乎是一个更好的选择,但与此同时,它似乎也非常令人困惑.

Do specific hosting providers host push server for you? Is there a way to get a server without having to host it? It seems like a much better choice over polling, but at the same time it seems extremely confusing.

是的,我为提供这种服务的 Pusher 工作.您可以在此处看到快速入门指南.还有其他实时托管服务您可以继续阅读.

Yes, I work for Pusher who offer such a service. You can see a quickstart guide here. There are also other realtime hosted services that you could read up on.

我还建议您看看:

  • My answer to How to Use Long Polling or Ajax Push in your Website - PHP focused
  • Using Comet with PHP
  • Implement Comet with PHP

我在第一个链接中表示,我认为PHP并不是用于实时Web应用程序的好技术.最好是拥有用作实时Web基础结构的不同组件.那应该是我自己工作的东西,或者是诸如 Pusher 这样的托管解决方案.为什么? PHP + Apache并非用于维护长时间运行的连接.您可以查看PHP独立的WebSocket解决方案,但是您有80%的人可能正在使用Apache,而有20%的nginx目前还不支持WebSockets(但很快就会使用).即使那样,我也不知道它们如何与标准的PHP请求/响应应用程序流集成.

My opinion, as expressed in the first link, is that PHP isn't a good technology for realtime web applications. You are best to either have different components that you use as your realtime web infrastructure. That should either be something self-installed or a hosted solution such as Pusher, who I work for. Why? PHP + Apache wasn't built for maintaining long running connections. There are PHP standalone WebSocket solutions you could look at, but you are 80% likely to be using Apache and 20% nginx which doesn't support WebSockets quite yet (but will soon). Even then, I'm not sure how they'll integrate with the standard PHP request/response application flow.

这篇关于AJAX/反向AJAX:轮询还是推送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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