I want to build a chat, based on JavaScript (jQuery will be used for AJAX) and PHP.
I’ve heard a good way of doing this is to use long-polling.
I do understand the idea, but I don’t know how to implement it on the server side.
An infinite loop sounds like a bad idea.
You don’t want to create an infinite loop, but you can set a timeout. Basically loop for X second waiting for some sort of data, and if that doesn’t happen send a response to the client telling it that it needs to initiate a new request, which will have the same timeout period.