PHP Flush: How Often and Best Practices

前端 未结 4 1323
梦谈多话
梦谈多话 2020-12-13 19:34

I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after the top portion of my page loads (head

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 20:12

    The technique described looks nice, but has several pitfalls:

    1) the time between PHP script start and end is small compared to transmission time; also, this saves the user about 0.5 seconds, according to your source. Is that a significant amount of time for you?

    2) this technique doesn't work with gzip output buffering

    3) if you flush too often, you'll be sending an almost-empty packet on flush, which might actually increase loading time (on slow, noisy connections).

    4) once you flush, you can't send any more headers

    5) (minor issue) the server response will come in chunked encoding, which means the client won't know the size in advance (therefore won't display "x% done" when downloading a file).

    On the other hand, if you expect your script to run for a loooong time (20+ seconds), it may be needed to send some data (spaces, for example) to keep the browser from timing out the connection.

提交回复
热议问题