문제

Can anyone explain how does the real time response works in Twitter ? Like when u search in twitter while viewing the result u get real-time updates saying "7 more people tweeted" . I have noticed there is no AJAX call being made. Can someone tell me how this works and is it possible to implement such a thing using PHP ?

도움이 되었습니까?

해결책

Firebug shows that it is making asynchronous calls to the server:

http://integratedsearch.twitter.com/search.html?_=1262187845554&q=new+year&since_id=7199106684&refresh=true&callback=processSummizeRefresh

Note the variables:

  • q: "new year"
  • since_id: 7199106684
  • refresh: true
  • callback processSummizeRefresh

All it's doing is looking for any matches to the q variable whose ID is greater than since_id and returning a count. If you load the results, by clicking "123 new tweets," the since_id will be updated to reflect the new latest ID value.

다른 팁

It's all about comet, as mentioned by Zack. Implementations in PHP are tricky; Facebook uses Erlang.

If you want to get started with PHP without the hassle of setting up your own server, check out WebSync On-Demand.

It's probably using long polling. See comet.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top