这个循环不会回显我的字符串

I have an infinite loop that I want to sleep for a second but the browser just hangs and nothing echos. Can someone tell me why?

while(1)
{
    sleep(1);
    echo 'test'.'<br>';
}

That's because PHP sends data to browser in big chunks. It is all about optimization, sending small data is bad for performance, you want it to be sent in huge enough blocks so overhead from transferring it (both in speed and actual traffic) would be relatively low. Couple of small strings is just not big enough. Try add a flush() right after the echo, it will force PHP send this string to the browser.

It won't work until the server stops processing.

You could try flushing the output buffer with flush(), but it's not guaranteed to work.

Try this function from PHP.net:

function flush_buffers() { 
    ob_end_flush(); 
    ob_flush(); 
    flush(); 
    ob_start(); 
} 

Couse it's a infinite loop it never will send response or be break