Q:

Ajax based chat - infinite server side loop

I have a chat on my page. I send the ajax post every 5 seconds to check the replies. Isn't there any better solution for it to avoid the sending too many requests?
Something like the infinite* loop on server.
PHP server side:
$i = 0
while(!$replies = checkNewReplies() && $i++<1000){        
    sleep(1);
}
echo json_encode($replies);
exit;

Wrong approach?

A:

I think there are number of possible solutions. You could look at long-polling (which is basically what you are doing).
Another alternative is to use something like XMPP which has some Javascript clients.  

