简体   繁体   中英

how to output php result in real time in browser?

I've created this code and it shows next integer every second but there are also errors along with the output.

<?php

ob_implicit_flush();
for ($i = 0; $i < 30; $i++) {
  echo "-> $i <br>\n";
  ob_end_flush();
  ob_end_clean();
  sleep(1);
}

?>

error:

Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in c:\apache\www\TEST.PHP on line 6
Notice: ob_end_clean(): failed to delete buffer. No buffer to delete in C:\apache\www\TEST.PHP on line 7
-> 4

Putting @ sign on the ob_* functions to silence these errors also disables realtime output.

You are ending ob_end_flush();

You should use only this:

ob_flush();

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