Pav
Pav

Reputation: 2328

Streaming Twitter API - how does it work?

I am currently implementing streaming twitter api using node.js & socket.oi

Wondering how does the streaming part actually work(on twitter end)? Lets say i want to implement my own live streaming service, using PHP/MySQL and get latest comments from db and display them live.

Any info/input would be greatly appreciated.

Thanks

Upvotes: 3

Views: 3052

Answers (1)

leggetter
leggetter

Reputation: 15467

The streaming Twitter API is an example of a HTTP Streaming API.

From Quora (linked to above):

HTTP Streaming is a technique used to push updates to a web client. A persistent connection is held open between the web client and the web server so that when the server has new information it can push it to the client. This is a truly persistent connection that will only drop due to network problems or through user action e.g. navigating away from a web page or the application is closed.

Looking at the response headers:

Content-Type:text/html; charset=iso-8859-1
Server:Jetty(6.1.25)
Transfer-Encoding:chunked

You can see it uses the Jetty web server.

Although this is achievable using PHP it's unlikely to scale all that well and won't be that efficient - which is why Twitter are using Jetty.

The way you'd achieve what you seem to be looking for would be to have your comment submitted and stored in your database and then push that comment onto a message queue of some sort. This message queue would be monitored by some kind of realtime technology (e.g. a process that works with Jetty), the message would be read from the queue and then streamed to any clients connected to your HTTP Streaming API.

Note: If you are just looking at pushing updates (i.e. realtime push, server push, push notifications) to clients (applications, web browsers) then a HTTP Streaming API is probably overkill

Upvotes: 5

Related Questions