简体   繁体   中英

php remove output buffering

I am doing a lot of processing at my PHP page and I want to display progress information to the user, for instance, finished 10% 20% and so. What is happening now is that all the data is displayed at once after processing is done, how can I display it right away!

I tried to set comment out output buffer in php.ini and I tried to use flush() after echo statements, not working, any suggestions?

Here is my code:

ob_start();
while ($line = read_file_line("c:/1.txt")) {  
  $read_lines_count++;
  if($read_lines_count % 100 == 0) {
    echo "parsed $read_lines_count <br />";
  ob_flush();
  }
}

First you need to call ob_start() before any code is printed.

Then echo whatever you want

call ob_flush() when you want to show the buffer on screen.

and at the end, a call to ob_end_flush() to end buffering and show output.

Make sure your php.ini has this line uncommented :

output_buffering = On

More Info : http://www.php.net/manual/en/book.outcontrol.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM