PHP将输出刷新到浏览器

我在一个PHP项目上工作,并使用flush().

我进行了大量搜索,发现PHP将大量的脚本输出以大块的形式发送到浏览器,并且在脚本终止时不会发送所有的大量数据.

我想知道此数据的大小,我的意思是,PHP将输出发送到浏览器必须输出多少字节.

解决方法:

不仅仅PHP会对数据进行分块;实际上,这是Apache(或Tomcat等)的工作.这就是为什么默认设置是关闭PHP中的“块”并将其留给Apache.即使您从PHP强制进行刷新,也仍然会被Apache困住.从手册中:

flush() may not be able to override the buffering scheme of your web
server and it has no effect on any client-side buffering in the
browser. It also doesn’t affect PHP’s userspace output buffering
mechanism. This means you will have to call both ob_flush() and
flush() to flush the ob output buffers if you are using those.

*上有一篇有关传输编码/分块的文章:http://en.wikipedia.org/wiki/Chunked_transfer_encoding

Apache使用GZIP或deflate编码变得更加复杂.您需要点击apache服务器以了解如何对其进行配置.

上一篇:为什么fprintf不直接写入文件,除非使用fflush()?


下一篇:写入后中止向磁盘缓慢刷新?