This article mainly introduces the method of PHP to realize instant output and real-time output content. This article directly gives the implementation method. Friends who need it You can refer to the following
The old man had a long chat. . Pure memo
For PHP programs that take a long time to run, you may need to output the content immediately to check the running status.
The code is as follows:
Header(“Content-type:text/html;charset=utf-8″);
#Set execution time without time limit
set_time_limit(0);
#Clear and close the buffer, use this function before outputting to the browser.
ob_end_clean();
#Control implicit buffering, the default is off. When turned on, the results of each print/echo or output command are sent to the browser.
ob_implicit_flush(1);
Example,
The code is as follows:
ob_end_clean();
ob_implicit_flush(1);
while(1){
//Some browsers require the content to reach a certain length before outputting it
echo str_repeat("
", 200).'hello sjolzy.cn
';
sleep(1);
//ob_end_flush();
//ob_flush();
//flush();
}
Tested according to the example, it achieved the effect of PHP outputting content in real time.