Php uses ob_flush to Output Principle Analysis every second. phpob_flush
This example describes how php uses ob_flush to output data every second. Share it with you for your reference. The specific analysis is as follows:
Functions:
The browser outputs a number every second.
Php. ini configuration:
Release 5.3
Implicit_flush = off
Output_buffering = off
Also, check whether output_buffering is enabled. You can:
Copy codeThe Code is as follows: var_dump (ini_get ('output _ buffering '));
Let's take a look at this Code:
<? Php $ I = 3; ob_start (); while ($ I --) {echo $ I, "<br/>"; ob_flush (); flush (); sleep (1);} ob_end_clean ();?>
But why: This Code cannot be output every second ??
Cause analysis:
Apache running principle: When you access an address (send a request) and apache starts PHP, php is executed at the page level, that is, if there is executable code: it is all executed before it is thrown to apache, and apache is then thrown to browser to display the result.
How to implement it?
What if the cli displays different results?
Linux cmd:
Php5 test. php
Directly executed by php without passing through apache or web service:
<? Php $ I = 3; while ($ I --) {echo $ I, "\ n"; sleep (1) ;}ob_end_clean () ;?>
I hope this article will help you with php programming.