title: Ajax post to PHP script that queries MySQL DB every 5 seconds performance/problems?
body: <p>I have a jQuery ajax function that posts to a PHP script which then retrieves some fields from the database and returns them to the client. The ajax function is run every 5 seconds after a button is clicked:</p>
  
  <pre><code>window.setInterval(function()
      {
          ajaxCall("lobby");
      }, 5000);
  </code></pre>
  
  <p>The ajax function:</p>
  
  <pre><code>function ajaxCall(param) 
      {
          $.ajax({
              url: "script/lobby.php",
              type: "post",
              dataType: "json",
              data: param,
              success: function(data, textStatus, jqXHR){
                  //do stuff with data
              },
              error:function(jqXHR, textStatus, errorThrown){
                  //show error
              }
          });
      }
  </code></pre>
  
  <p>Is this a good way of doing it? I have read somewhere that if done wrongly it may create a backlog of calls. How would I prevent that or is there a better way instead of querying a database every 5 seconds for each user?</p>