Yahoo的Flush the Buffer Early 思想!
2010-05-06 18:43
337 查看
When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefit is mainly seen on busy backends or light frontends.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
... <!-- css, js --> </head> <?php flush(); ?> <body> ... <!-- content -->
PHP官方的flush()说明
是将截止目前,程序的所有输出 打印出去。 这样,PHP下面的代码即便没有执行完毕,也会输出一部分代码。
例如
网页要即时计算一些数据,打印给网民。
我们先将HTML的<header>打印出去,然后再打印boay的内容。这样就提高了一定量的速度哦~~
相关文章推荐
- Stack is one important segment of the process’s memory layout. It is a dynamic memory buffer portion
- The Input Buffer & scanf()
- python3中split分割字符串出现错误 TypeError‘str’ does not support the buffer interface
- [MySQL] Buffer Pool Adaptive Flush
- flume报错:Sinks are likely not keeping up with sources, or the buffer size is too tight
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- CRT detected that the application wrote to memory after end of heap buffer
- CRT detected that the application wrote to memory after end of heap buffer
- SwapBuffers glutSwapBuffer glFlush glFinish
- null id in XXXentity (don't flush the Session after an exception occurs。。。。(HIbernate 实体类包含关键字)
- Client-side Write Buffer 使用table.setAutoFlush(false)
- The Beauty of DirectX 11 --- constant buffer, buffered/structure buffer
- How do I get the “Command Buffer” in Solaris 10?
- IEEE极限编程之The pipeline-动态规划思想
- acdream 1116 Gao the string! (扩展kmp,dp思想,矩阵优化)
- CRT detected that the application wrote to memory after after the end of heap buffer
- 关于buffer,cache,wb,wt,clean,inv,flush,以及其他
- [MYSQL] ERROR: cannot allocate the memory for the buffer pool
- 转:从《The C Programming Language》中学到的那些编程风格和设计思想
- poj 2057 The Lost House 贪心思想在动态规划上的应用