Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
81 views
in Technique[技术] by (71.8m points)

Display output in parts in PHP

I have this code:

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

?>

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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); 
}

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...