Home >Backend Development >PHP Tutorial >PHP cannot output principle analysis every second when using ob_flush, phpob_flush_PHP tutorial

PHP cannot output principle analysis every second when using ob_flush, phpob_flush_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:51:52858browse

php cannot output principle analysis every second when using ob_flush, phpob_flush

The example in this article tells that php cannot output principle every second when using ob_flush. Share it with everyone for your reference. The specific analysis is as follows:

Function implementation:

The browser outputs a number every second.

php.ini is configured as:

Version 5.3

implicit_flush = off
output_buffering = off

Another: Check whether output_buffering is turned on, you can:
Copy code The code is as follows: var_dump(ini_get('output_buffering'));

Okay let’s take a look at this code again:

<&#63;php
  $i = 3;
  ob_start();
  while ($i--) {
    echo $i, "<br />";
    ob_flush();
    flush();
    sleep(1);
  }
  ob_end_clean();
&#63;>

But why: this code cannot be output every second? ?

Cause analysis:

Apache operating principle: When you access an address (send a request), apache starts PHP, then PHP execution is at the page level, that is, if there is executable code: it will be thrown to apache after it is all executed, and apache will Throw it to the browser to display the results

How to achieve it?

If the cli displays the results in a different way, what’s the difference?

linux cmd:

php5 test.php

It can be implemented directly by php without going through apache or web service:

<&#63;php
  $i = 3;
  while ($i--) {
    echo $i, "\n";
    sleep(1);
  }
  ob_end_clean();
&#63;>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1011251.htmlTechArticlephp cannot output principle analysis every second when using ob_flush, phpob_flush This article tells an example that php cannot use ob_flush every second Second output principle. Share it with everyone for your reference. Detailed analysis...
Statement:
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