Home  >  Article  >  Backend Development  >  PHP realizes instant output and real-time output content method_PHP tutorial

PHP realizes instant output and real-time output content method_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:52:311739browse

PHP methods to achieve instant output and real-time output content

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1007651.htmlTechArticlePHP methods to achieve instant output and real-time output content. 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 can refer to...
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