Home > Backend Development > PHP Tutorial > About the use of ob_flush() and flush() in php

About the use of ob_flush() and flush() in php

WBOY
Release: 2016-07-25 09:05:45
Original
1131 people have browsed it
Note: The two functions ob_flush() and flush() are generally used together. The order is ob_flush() first, then flush(). Their function is to refresh the buffer. Here is a detailed explanation of when to use the refresh buffer and why to refresh the buffer.

Note: The two functions ob_flush() and flush() are generally used together. The order is ob_flush() first, then flush(). Their function is to refresh the buffer. Here is a detailed explanation of when to use the refresh buffer and why to refresh the buffer.

1. When to refresh the buffer When the two functions file_get_contents() and file_put_contens() are used in the program, or when the program performs similar "read and write" functions or performs output operations to the browser, ob_flush() and flush() will be used to refresh buffer.

2. Why should we refresh the buffer? Use file_get_contents() and file_put_content() as examples to explain.

The two functions file_get_contents() and file_put_conents() perform reading and writing data operations respectively. The data is first read into the memory and then written to the file, because the reading speed is faster than the writing speed. Fast, so when your data is read, it does not mean that the data has been written. At this time, the more read content will be temporarily placed in the buffer (memory). It needs to be emphasized here that in fact, data reading and Writing is two very fast actions.

Also explained (when the program performs an output operation to the browser), individual web server programs, especially web server programs under Win32, will still cache the output of the script until the end of the program before sending the results to the browser until. If you don't want the program to be output to the browser only after it is executed, then you can also use ob_flush() and flush() to refresh the cache.

In fact, flush() has another use, which is to output before the program ends. That is, part of the results can be output to the browser before a loop ends. This effect is very similar to the asynchronous transmission effect of ajax.



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