I take it the deletion of the previous topic means that you got the nl2br() function to work as you wanted it to.
If this is an instant messaging program, it's pointless having an endless loop, as the data is not sent to the client until the page has finished output.
What you should consider doing, as I assume this is a javascript based chat client (although it can be done with plain HTML) is to call the filesize (well, when I made one, I called the MD5 of the file, as with filesize cheese and ceeehs will give the same filesize, and not update) into the script and check it there, THEN refresh the page.
Erm, you're probably wondering what the hell I'm on about, and if thats the case, disregard the above 😛