PHP implements Real-Time Output and Real-Time Output content methods
This article mainly introduces PHP's methods for implementing real-time output and Real-Time Output content. This article provides the implementation method directly. For more information, see
Let's talk about it .. Pure memo
For PHP programs that run for a long time, you may need to output the content in real time to view the running status.
The Code is as follows:
Header ("Content-type: text/html; charset = UTF-8 ″);
# Setting the execution time is not limited
Set_time_limit (0 );
# Clear and close the buffer and use this function before outputting it to the browser.
Ob_end_clean ();
# Control implicit buffering. The default value is off. When it is enabled, the results of each print/echo or output command are sent to the browser.
Ob_implicit_flush (1 );
For example,
The Code is as follows:
Ob_end_clean ();
Ob_implicit_flush (1 );
While (1 ){
// Some browsers need to output the content after it reaches a certain length.
Echo str_repeat ("
", 200). 'Hello sjolzy.cn
';
Sleep (1 );
// Ob_end_flush ();
// Ob_flush ();
// Flush ();
}
The test by example achieves the Real-Time Output of PHP content.