Introduction to the differences between flush(), ob_flush(), and ob_end_flush() in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:12:46
Original
801 people have browsed it

The difference between flush(), ob_flush(), and ob_end_flush():

First of all, let’s talk about the buffer. It is a memory address space, which is 4096 (1kb) [in the php.ini configuration file Find the output_buffering configuration], PHP has a php output_buffering mechanism. When the PHP code is executed, it does not output the content immediately, but wants to output the echo/print content to the buffer. When the buffer is full, the data will be handed over to the system kernel. It is passed to the browser through tcp for display. When the php php output_buffering mechanism is turned on (it is turned on by default and can be turned on through the ob_start() function), only when the data in the php buffer reaches the set value, the data in the buffer will be sent to the browser.

But browsers also have caches. Some versions of browsing only output content when the data reaches 256 bytes. flush() can immediately send the content waiting to be output to the client, while ob_flush() can only wait for the buffer Output only when full.

Here is a simple example for you to verify:

Copy code The code is as follows:

//Prevent browser caching
echo str_repeat(" ",1024);
for($i=0;$i<5;$i++){
echo $i;
sleep(1);
flush();/ / will output a number every 1s. If ob_flush() is used, it will wait for 5s and output together
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326610.htmlTechArticleThe difference between flush(), ob_flush(), and ob_end_flush(): First, let’s talk about buffer, which is A memory address space, 4096 (1kb) [Find the output_buffering configuration in the php.ini configuration file...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!