I'm very new to server push technologies (websockets, socket.io, sockjs) so this is probably a very newbie question. However, my google-fu has not been strong enough to find the answer.
I'm writing, using PHP server-side and javascript client-side, an "event ticker" application. It works like this:
- When the user logs in, the server sends him the last 10 events. This is easy!
- Then, the server sends the user new events as they come in. This is what I'm having trouble figuring out.
Right now, I have the events stored in a database. How does the server figure out which events are "new" and which are "old" (i.e. have already been sent to the client)? Is it as simple as having a boolean column in the DB for each event?
Edit: To clarify my question: I know how to set up the server push client side... actually, websockets, sockjs and socket.io all have identical API, they were designed that way. I also know how to set up PHP to run in an event loop. There are tutorials on this. Python, Ruby and Javascript don't have native support for this either, and use non-native frameworks to do it.
My question is specifically about the details of the database interaction: for example, how does my server-side script know that the database has been updated? Polling the database is the only solution that I can think of, but that seems non-optimal. I'm using MySQL, so it's not an event-driven database. The reason I'm using MySQL is that the rest of the website uses MySQL. Bad choice? Should I be looking at transitioning to a different DBMS? Or can MySQL be made to work in this application?