如何Gmail的定期邮件抓取工作? [英] How does Gmail's periodic mail fetching work?

查看:112
本文介绍了如何Gmail的定期邮件抓取工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Gmail时,一些我刚刚收到的新邮件在收件箱中,即使我没有刷新页面。我相信会在阿贾克斯完成。

When I am using gmail, some new mails that I just received appear on the inbox, even if I did not refresh the page. I believe that would done in Ajax.

有没有什么好的演示,作品非常相似呢?定期检查和获取JSON数据(我不知道这是否是JSON数据..),以获取新的数据??

Is there any good demo that works very similar to it? Periodically checking and getting JSON data (I am not sure if it is JSON data..) to fetch new data??

谢谢!

推荐答案

与定期更新的问题是,虽然它是很好的一些事情是不是太浪费时间关键,如电子邮件抓取,它不是瞬间。因此,你不会想使用它像聊天,其中一个响应太长等待甚至五秒钟。你可以减小轮询间隔,并要求一旦第二甚至半秒,但随后你会很快超载您的浏览器和资源浪费。

The problem with periodic refresh is that while it is good for some things that aren't too time critical, like e-mail fetching, it is not instantaneous. Therefore you wouldn't want to use it for something like chat where waiting even five seconds for a response is too long. You could decrease the polling interval and make a request once a second or even half second, but then you'd quickly overload your browser and waste resources.

有这样的一个解决方案是使用一个称为AJAX长轮询(由他人为彗星或反向AJAX'已知的)的技术。利用这种技术,浏览器发出一个持续时间长的AJAX请求,一个不返回,直到有新的数据可用。该请求位于服务器(你需要运行特殊的服务器端软件来处理这个在一个可扩展的方式,但你可以用PHP砍东西一起作为示范),直到新的数据可用,此时它返回到客户端新的数据。当客户端接收数据它使另一个长轮询请求坐在服务器,直到有更多的数据。这是Gmail使用的方法,我相信。

One solution for this is to use a technique called ajax long polling (known by others as 'comet' or 'reverse ajax'). With this technique, the browser makes a long duration ajax request, one that does not return until there is new data available. That request sits on the server (you need to be running special server side software to handle this in a scalable manner, but you could hack something together with php as a demonstration) until new data is available at which point it returns to the client with the new data. When the client receives the data it makes another long polling request to sit at the server until there is more data. This is the method that gmail uses, I believe.

这是长轮询的要点,你必须做一些修改,因为大多数浏览器将到期Ajax请求,如果它不经过较长时间恢复,所以如果Ajax请求超时,客户端必须再拍请求(但超时通常是在一分钟或更长的时间间隔)。但是,这是主要的想法。

That is the gist of long polling, you have to make a couple of modifications because most browsers will expire an ajax request if it does not return after a long time, so if the ajax request times out the client has to make another request (but the timeout is usually on the interval of a minute or longer). But this is the main idea.

服务器端实现的,这是远远超过了客户端更复杂(客户端需要的JS只有几行)。

The server side implementation of this is far more complicated than the client side (client side requires just a few lines of js).

这篇关于如何Gmail的定期邮件抓取工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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