


In-depth understanding of the difference between ob_flush and flush (how to use ob_flush() and flush())_PHP tutorial
About how to use ob_flush() and flush() in php
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 flush the buffer.
2. Why 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 into the file, because the reading speed is faster than writing. The speed must be 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 Fetching and writing are two very fast actions.
Also to use an explanation (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 before sending the results to the browser until until the program ends. 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.
In-depth understanding of the difference between ob_flush and flush
The description of ob_flush/flush in the manual both refreshes the output buffer and needs to be used in conjunction, so it will cause Many people are confused...
In fact, they operate on different objects. In some cases, flush does nothing at all..
ob_* series of functions operate the output buffer of PHP itself. .
So, ob_flush refreshes PHP's own buffer.
And flush, strictly speaking, this can only be done when PHP is installed as an Apache Module (handler or filter). It has a practical effect. 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 indirectly call the api of apache by calling the flush member function pointer of sapi_module: ap_rflush refreshes the output buffer of apache. Of course, the manual also says that there are some other modules of apache that may change the result of this action.
Some Apache modules, such as mod_gzip, may perform output caching by themselves. , 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. Therefore, use both correctly The order is. First ob_flush, then flush,
Of course, under other sapi, you can not call flush, but to ensure the portability of your code, it is recommended to use it together.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

Export password-protected PDF in Photoshop: Open the image file. Click "File"> "Export"> "Export as PDF". Set the "Security" option and enter the same password twice. Click "Export" to generate a PDF file.

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
