I am creating live chat in PHP that will allow all members to chat with each others.
What I am doing now is basically when the member send a chat message, the server record it in the database.
Each client make HTTP request when the page load, the server delay the response until there is a new message that was recorded in the database, then it delete the message and response to the HTTP request with the chat message.
The server keep looping to check if any message is avaiable in the database, I found that the apache was using (66% +) CPU when ONLY one member is online, so I added sleep() method between each loop like the following:
// Code here to check if any new chat message is avaiable in the database...
I tested with one member again after adding sleep() method and now I see it's working normally.
In the case the I have alot of members online (ex: 100,000 online members) I have doubts that this way could cause the server CPU to be used incredibly since it keep processing the above code for each online member.
Is that way will highly affect on the server performace?
Do you recommend using it or not?
What CPU and RAM is more suitable to run website that use that way?