title: Server push: how does server tell if message has already been sent to client?
body: <p>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.</p>
  
  <p>I'm writing, using PHP server-side and javascript client-side, an "event ticker" application. It works like this:</p>
  
  <ol>
  <li>When the user logs in, the server sends him the last 10 events. This is easy!</li>
  <li>Then, the server sends the user new events as they come in. This is what I'm having trouble figuring out.</li>
  </ol>
  
  <p>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?</p>
  
  <p><strong>Edit:</strong> 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.</p>
  
  <p>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?</p>