title: How to make a javascript/php chatroom more efficient in terms of load time and sql communication
body: <p>Right now the setup for my javascript chat works so it's like</p>
  
  <pre><code>function getNewMessage()
  {
       //code would go here to get new messages
       getNewMessages();
  }
  getNewMessages();
  </code></pre>
  
  <p>And within the function I would use JQuery to make a get post to retrieve the messages from a php scrip which would
  1. Start SQL connection
  2. Validate that it's a legit user through SQL
  3. retrieve only new message since the last user visit
  4. close SQL</p>
  
  <p>This works great and the chat works perfectly. My concern is that this is opening and closing a LOT of SQL connections. It's quite fast, but I'd like to make a small javascript multiplayer game now, and transferring user coordinates as well as the tens of other variables 3 times a second in which I'm opening and closing the sql connection each time and pulling information from numerous tables each time might not be efficient enough to run smoothly, and might be too much strain on the server too.</p>
  
  <p>Is there any better more efficient way of communicating all these variables that I should know about which isn't so hard on my server/database?</p>