Echo from php "how does it go"

What was the way to print the results with php script while it prints material before the script ends? I tried playing with the output buffer by putting sleep () between echos to check, but the result is always displayed after the script is executed. Is this also the side of the browser?

+3
source share
6 answers

All you could do in your PHP script to try to clear all current output in the user's browser is a call ob_flush, but it really depends on many other things.

The HTTP server has its own buffering, and the browser cannot instantly display every packet received. This is like a long pipeline of buffers at different levels that need to be cleared before you see anything in the browser, and the PHP output buffer is at the highest level.

+4
source

yes you can do it this way

<?php
 echo "hello senad";
 flush();
 sleep(20);
 echo "meskin";
?>
+3
source

PHP - . -, script .

script , , , script. , .

+1

2 :

1) output_buffering php.ini

2) , :

for ($i = 1; $i <= 3; $i++) {
  echo md5(rand())."<br />";
  flush(); 
  ob_end_flush();     
  sleep(1);
}
+1

PHP , . flush() script.

0
source

Good question .. when I want to do something like this (like loggin actions), I just use AJAX. And I know that this is not what you wanted, but listen to me. I also had a problem 4 times, and I used AJAX, and because of this, I managed to install preloader (which is really cool and useful :))

"Use ajax" I mean, if you have 4 actions to show 4 ajax requests. I know that this is not the most elegant solution (as you do a lot of unnecessary things), but it is a good constructive solution.

0
source

Source: https://habr.com/ru/post/1794835/


All Articles