I'm using Debian 13 with Nginx 1.26.3 and SSE (Server Sent Event) and PHP. What I tried to achieve is to have many connections to clients. But I have not all the time something to sent to the clients! What I read in the ducumentation is that the server has to hold the connection, until new data available for sending. I did it in the following way:
while($lastTime == $_SESSION['lastTime']{
sleep(10);
}
In SESSION is the lastTime stored, when the server has created new data and in $lastTime is stored, the lastTime of the last data packet the client has received. If the SESSION['lastTime'] is changing, new data are available.
But it doesn't work! The loop will never end, because the PHP script can't receive new data as long the script is in the while loop. And therefore the SESSION['lastTime'] will not be updated!
I was thinking that several copy of the same script can run. But that seems to be not the case! Is there another way to hold the connection to the server? Sorry if this is a simple question, but I don't have the neccessary understanding.
If only ony copy can run on the same time, how can the server hold several connections?