Home > Backend Development > PHP Tutorial > Solution to the problem that php ob_flush cannot output every second

Solution to the problem that php ob_flush cannot output every second

WBOY
Release: 2016-07-25 08:58:55
Original
863 people have browsed it
  1. $i = 3;
  2. ob_start();
  3. while ($i--) {
  4. echo $i, "
    ";
  5. ob_flush();
  6. flush ();
  7. sleep(1);
  8. }
  9. ob_end_clean();
  10. ?>
Copy code

Question: Can’t this code be output every second? Cause Analysis: Apache operating principle: After accessing an address (sending a request), PHP is started in the apache server. PHP execution is at the page level. If there is executable code: After it is all executed, it is thrown to apache, and apache is thrown to the browser to display the results.

Solution: If the cli displays results in a different way, what's the difference? linux cmd: php5test.php It can be implemented directly by php without going through apache or web service:

  1. $i = 3;
  2. while ($i--) {
  3. echo $i, "n";
  4. sleep(1);
  5. }
  6. ob_end_clean();
  7. ?> ;
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template