Ignore_user_abort (TRUE);//whether to continue executing the script header (' content-type:text/html;charset=utf-8 ') without ignoring the browser's disconnection; Echo Str_pad ("", ); Output 1000 spaces (the browser needs to accept a certain length of data before the content is output) echo ' Begin ...
'; Ob_flush (); flush (); for ($i =0; $i <10; $i + +) { echo ' loading '. $i. ' 0%
'; if (connection_aborted ())//Check whether the client is disconnected. If the connection is terminated, the function returns 1, otherwise 0 { exit; } Ob_flush (); Flush (); Sleep (1);//Sleeping One Second} echo ' OK ';
/*
First, clear the output sequence of PHP
1. PHP output cache is turned on: Echo,print, PHP output_buffring, server buffering, browser buffering display
2. PHP output Cache is not open: Echo,print, server buffering, browser buffering, browser display
Also clear the browser output cache: IE 256Bytes, Chrome and Firefox 1000Bytes, only the output data reached this length or script end browser will be output data on the page
Again, there are several PHP settings and APIs that you can use:
Output_buffering configuration in the 1.php.ini
? Off: Indicates that the PHP output cache is turned off
? On: Open an infinitely large output cache
? 4096: Open output cache with size 4096Byte
Implicit_flush configuration in the 2.php.ini
? On: Indicates that the flush () function is automatically called after each output (such as echo,print) and is output directly
? OFF: On the contrary, flush () is not called after each output, and it needs to wait until the server buffering is full before it is output, but we can replace it with the flush () function, which is more flexible instead of opening.
3.ob_flush () function: Take out the data in PHP buffering and put it into the server buffering
4.flush () Function: Remove the data from the server buffering and put it into browser buffering
5.ob_start () function: Opens a buffer on the server to hold all output. So at any time using echo, the output will be added to the buffer until the end of the program run or using Ob_flush (). The contents of the buffer in the server are then sent to the browser, which is parsed by the browser to display
The Ob_* series function is the output buffer that operates PHP itself.
Ob_get_contents ()-Returns the contents of the output buffer
Ob_flush ()-Flushes out (sends out) the contents of the output buffer
Ob_clean ()-Empty (erase) the output buffer
Ob_end_flush ()-Flushes out (sends out) the output buffer contents and turns off buffering
Ob_end_clean ()-Empty (erase) buffer and turn off output buffering
Flush ()-Refreshes the output buffer
Summarize:
Ob_flush is the buffer that refreshes PHP itself.
The function Ob_end_clean clears the contents of the buffer and closes the buffer, but does not output the content.
You have to use a function ob_get_contents () before Ob_end_clean () to get the contents of the buffer.
In this case, you can save the content to a variable before executing ob_end_clean (), and then you will be able to handle the variable after Ob_end_clean ().
Can be used to cache static HTML content
Note: Flush, strictly speaking, this only works when PHP is installed as an Apache module (handler or filter). It is a buffer that refreshes the webserver (which can be considered specifically Apache).
1. Under Apache module's SAPI, flush will call Sapi_module's flush member function pointer, calling Apache's Api:ap_rflush to flush the Apache output buffer indirectly.
Of course the manual also says that there are some Apache other modules that may change the results of this action.
2. Some Apache modules, such as Mod_gzip, may make their own output caches, which will result in the flush () function producing results that are not immediately sent to the client browser.
Even the browser will cache the received content before it is displayed. For example, the Netscape browser caches content before it accepts the start of a newline or HTML tag, and receives aThe entire table is not displayed until the tag is marked.
3. Some versions of Microsoft Internet Explorer do not start to display the page until the 256 bytes are accepted, so you must send some extra spaces to let these browsers display the page content.
So, the correct use of the two is the order. Ob_flush first, then flush.
Of course, in other sapi, do not call flush also can, only to ensure that your code portability, recommended for use.
*/
Data Source:
http://bbs.csdn.net/topics/310167610
http://my.oschina.net/miaowang/blog/349290
Http://www.cnblogs.com/daxian2012/archive/2012/09/12/2682136.html
Thank you for your selfless sharing!
The above describes the PHP side of the output data collation, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.