Home  >  Article  >  Backend Development  >  PHP line-by-line output (combination of ob_flush and flush)_PHP tutorial

PHP line-by-line output (combination of ob_flush and flush)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:21:49954browse

The description of ob_flush/flush in the manual is that they both refresh the output buffer and need to be used together, so it will cause confusion to many people...
In fact, they operate on different objects. In some cases, flush does nothing at all. Things...
ob_* series functions operate the output buffer of PHP itself.
So, ob_flush refreshes PHP's own buffer.
Strictly speaking, flush can only be used in PHP. It only has practical effect when the apache Module (handler or filter) is installed. It refreshes the buffer of the WebServer (which can be considered to refer specifically to apache).
Under the sapi of the apache module, flush will call the flush member of sapi_module Function pointer, indirectly calls Apache's API: ap_rflush refreshes Apache's output buffer. Of course, the manual also says that there are some other Apache modules that may change the result of this action.
Some Apache modules, such as mod_gzip, may do its own output caching, which will cause the results produced by the flush() function to not be sent to the client browser immediately.
Even the browser will cache the received content before displaying it. For example, the Netscape browser caches content until it receives a newline or the beginning of an html tag, and does not display the entire table until it receives a tag.
Some versions of Microsoft Internet Explorer will only start displaying the page after receiving 256 bytes, so some extra spaces must be sent to allow these browsers to display the page content.
So, the correct order to use the two is. First ob_flush, then flush,
Of course, under other sapi, you can not call flush, but in order to ensure the portability of your code, it is recommended to use them together.
In IE, 256 bytes must be output first before it will work. The following code:

Copy the code The code is as follows:

function execte(){
echo str_pad(" ", 256);
for ($i=1;$i<10;$i++){
echo $i."< Br>";
ob_flush();
flush();
sleep(1);
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324861.htmlTechArticleob_flush/flush described in the manual is to refresh the output buffer, and also needs to be used in conjunction, so it will It has caused confusion to many people... In fact, they operate on different objects. In some cases...
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