PHP Function Flush
The php function flush is used to immediately send the buffered output of a script to the browser and client. This is especially helpful for real-time updating or optimizing content delivery. It is also useful to avoid some pitfalls, like browser caching.
Output buffering is a feature of PHP that allows the server to hold the contents of echo statements until the end of the script. This allows the server to respond more quickly, and it also reduces the number of output lines sent to the browser. Buffering can be turned on or off by setting the directive output_buffering in your php. Buffers can also be nested, so even if you turn off buffering in your code, you may find that your server is still buffering the output.
Some servers use a large buffer to hold a single page for long periods of time. This can cause a delay in sending the page to the browser, so it is important to understand how this works and how to use the flush function to minimize this issue.
The flush function can be confusing to understand because it will not necessarily clear all of the buffered data. Depending on the server configuration, this could leave a copy of the buffer in the browser or cache. This is why it is best to run a test script to see how it behaves on the server you are running on. This will give you an idea of how effective the flush function is.