You can check the accepted answer for the next post, which describes a very simple example of how to implement Long Polling using php on the server side:
When using Long Polling, your client application launches a request to an HTTP server with an infinite timeout (or very long). Now, as soon as new data appears, the server will find the active connection ready so that it can instantly output the data. In a traditional survey, you will have to wait until the application initiates a new poll, as well as the network timeout, to get to the server before sending new data.
Then, when the data is sent, the connection is closed, but your application should immediately open a new one in order to have a permanent open connection to the server. In fact, there will be a very small gap where there will be no active connection, but this is often negligible in many applications.
source share