显示PHP部分输出 [英] Display output in parts in PHP

查看:70
本文介绍了显示PHP部分输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

<?php
for($i = 0; $i<30; $i++)
{
    echo "$i<br>";          
    usleep(100000); 
}

?>

我想知道如何使浏览器显示0,然后显示1,然后显示2,...

I would like to know how make the browser display 0, then 1, then 2, ...

在我的示例中,它会加载一段时间,然后显示0-29.

In my example, it loads for a while and then display 0-29.

推荐答案

禁用所有输出缓冲并填充输出:

Disable all output buffering and pad the output:

while(@ob_get_clean());

for($i = 0; $i<30; $i++)
{
    echo str_pad("$i<br>",4096);          
    usleep(100000); 
}

此外,如果您的Apache使用的是mod_deflate,并且您对text/html文件使用gzip压缩,则此操作将无效.

Also, this won't work, if your Apache is using mod_deflate and you have gzip-compression for text/html files.

这篇关于显示PHP部分输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆