This article mainly introduces the principle that php uses ob_flush to output data every second. It analyzes in detail the principles related to php's use of ob_flush and how to use cli in Linux, for more information, see
This article mainly introduces the principle that php uses ob_flush to output data every second. It analyzes in detail the principles related to php's use of ob_flush and how to use cli in Linux, for more information, see
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:
The 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 ,"
"; 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 will be discarded to apache after all execution, and apache will be discarded 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.