PHP buffer why \r\n

前端 未结 3 1709
花落未央
花落未央 2020-12-07 04:30

I have a few conceptual questions (all related, I think) regarding the following script, at the comments. The script works fine.



        
3条回答
  •  春和景丽
    2020-12-07 04:59

    First, why do I need to send the \r\n\r\n to the browser? I assume it has something to do with headers.

    Second, why do I need some HTML in the middle?

    Normally browser have to wait until they have fetched the whole response until it can be rendered (just think of XML that can be valid until the last character). But since that would make a bad user experience, most browsers start to parse and render the contents as early as possible.

    And here this HTML fragment could be the initiator for the browser to actually build the DOM and start rendering.

    Third, there are many examples that use 256 bytes instead of 4096. However, the script doesn't work if I use 256. Are these examples outdated, and will this number change again in the future?

    As the manual hints that there might be some further buffering incorporated in the web server, this might be the attempt to overflow those buffers that they are also flushed in order to have the expected effect.

提交回复
热议问题