title: How to scale my chat application?
body: <p>I have a website that is implemented in php/mysql, and is hosted at hostmonster (<em>shared hosting</em>).</p>
  
  <p>I am planning to incorporate a chat feature in my website, that enables users to chat with each other. There are approx. 1000 users on my site.
  Currently, i have implemented an ajax strategy that sends requests to the server on a periodical basis (say, every 4 seconds) to get the json response about online users and messages.</p>
  
  <p>This is the sample code that sends requests:</p>
  
  <pre><code>var timer, delay = 4000;
  
  timer = setInterval(function(){
      $.ajax({
        type: 'POST',
        url: 'update.php?user_id=2',
        success: function(html){
          $('.chat_messages').append(html);
        }
      });
  }, delay);
  </code></pre>
  
  <p>But as i see, more the number of users, more the requests for every 4 seconds, and more burden on Apache server and database to deliver the response.</p>
  
  <p>So i am planning for an alternate solution, that has no overhead on the server.
  I have heard about few servers like APE, Nginx, Node.js, StreamHub that use COMET/reverse ajax technology to serve the requests, and are efficient for my purpose.</p>
  
  <p>But the problem is that, i dont have permission to install a third party server on my hostmonster cpanel.
  Is there any other way around, like HTML5 web sockets?</p>
  
  <p><strong>EDIT:</strong> By the way, i am also interested to rebuild my application on Java, if there is a viable solution.</p>