Improvement in Chat application


I am developing a chat for my site where a user sends an invitation to the other user, if it accepts it will open and the system will be checking for new messages.

For the system to do this, I use a while , and while it does not return any results, I get the last id of the memory that I received, I create a query to bring results greater than the id provided. After executing a retry and not returning anything I give a sleep of 1 second in the to not overload.

I wonder if anyone could build a chat with a different system and how did he do it? Is there any technique that is more performative than long-polling ?

asked by anonymous 04.12.2015 / 20:01

1 answer


This practice you are applying makes the application unusable, as it will hold the until you get a message, giving you a great chance to give timeout .

The best move in this case would be to use websockets . Here's an example: link

04.12.2015 / 20:07