I believe that the accepted answer may be misleading . Although it answers the question correctly (how to adjust the 1st interval), it is not true that an infinite loop is a bad approach in general.
SSE is used to receive updates from the server when there are actually updates that are opposite to the Ajax poll, which constantly checks for updates (even if there are none) at regular intervals. This can be done using an endless loop that maintains the server side of the script all the time, constantly checks for updates and selects them only in case of changes.
It is not true that:
The browser will not see any event data while the script is still running.
You can run the script on the server and still send updates to the browser without ending the script as follows:
while (true) { echo "data: test\n\n"; flush(); ob_flush(); sleep(1); }
Executing it, sending the retry parameter without an infinite loop, the script will end, and then run the script again, run it, run it again ... This is like checking an Ajax poll for updates, even if they are not there and this is not how the SSE is designed for work. Of course, there are some situations where this approach is suitable, as indicated in the accepted answer (for example, expecting the server to create a PDF file and notify the client when it does).
Using the infinite loop method will support the script on the server all the time, so you have to be careful with a lot of users, because you will have a script instance for each of them, and this can lead to server overload. On the other hand, the same problem can happen even in some simple scenario, when you suddenly get a bunch of users on a website (without SSE) or if you use web sockets instead of SSE. Everything has its limitations.
Another thing to take care of is what you put into the loop. For example, I would not recommend placing the database query in a loop that runs every second, because then you also put the database at risk of overload. I would suggest using some kind of cache (Redis or even a plain text file) for this case.