Php side execution side output data sorting

Source: Internet
Author: User
: This article mainly introduces how to organize php execution and output data. For more information about PHP tutorials, see.
// Ignore_user_abort (true); // whether to ignore the browser disconnection and continue executing the script header ('content-Type: text/html; charset = utf-8 '); echo str_pad ("", 1000); // output 1000 spaces (the browser needs to accept data of a certain length before outputting the content) 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 has been terminated, 1 is returned; otherwise, 0 {exit;} ob_flush (); flush (); sleep (1); is returned ); // sleep for one second} echo 'OK ';
/*
First, clarify the PHP output sequence
1. open the php output cache: echo, print-> php output_buffring-> server buffering-> browser display
2. php output cache not enabled: echo, print-> server buffering-> browser display
In addition, it is clear that the browser's output cache: IE is 256 Bytes, Chrome and FireFox are 1000 Bytes. the browser will output the data on the page only when the output data reaches this length or the script ends.
Let's talk about several PHP settings and APIs used:
1. output_buffering configuration in php. ini
? Off: disables the PHP output cache.
? On: Open the infinite output cache
? 4096: Open the output cache with a size of 40 96 bytes
2. implicit_flush configuration in php. ini
? On: indicates that after the flush () function is automatically called after each output (such as echo, print), the output is directly
? Off: in contrast to On, flush () is not called after each output. it is output only when the server buffering is full, but we can replace it with the flush () function, it does not matter if it is not enabled, but it is more flexible.
3. ob_flush () function: extracts data from PHP buffering and places the data in server buffering.
4. flush () function: extracts Server buffering data and places it in browser buffering.
5. ob_start () function: open a buffer on the server to save all the output. Therefore, when echo is used at any time, the output will be added to the buffer until the program running ends or the end ends with ob_flush. Then, the buffer content in the server will be sent to the browser for resolution and display by the browser.
Ob _ * series functions are used to operate the output buffer of PHP itself.
Ob_get_contents ()-return the content of the output buffer
Ob_flush ()-extracts (Sends) the content in the output buffer.
Ob_clean ()-Clear (erase) output buffer
Ob_end_flush ()-extracts (Sends) the output buffer content and closes the buffer.
Ob_end_clean ()-Clear (erase) the buffer and disable the output buffer.
Flush ()-refresh the output buffer
Summary:
Ob_flush is the buffer for refreshing PHP itself.
The ob_end_clean function clears the buffer and closes the buffer, but does not output the content.
In this case, you must use the ob_get_contents () function to obtain the buffer content before ob_end_clean.
In this way, you can save the content to a variable before executing ob_end_clean (), and then perform operations on the variable after ob_end_clean ().
Can be used to cache static html content
Note: flush, strictly speaking, this is only useful when PHP is installed as an apache Module (handler or filter. it is used to refresh the buffer zone of the WebServer (which can be considered to be specific to apache.
1. in the sapi of apache module, flush indirectly calls apache api: ap_rflush to refresh apache output buffer by calling the flush member function pointer of sapi_module,
Of course, the manual also said that some other apache modules may change the results of this action ..
2. some Apache modules, such as mod_gzip, May output the cache by themselves, which will cause the results produced by the flush () function to be not immediately sent to the client browser.
Even the browser caches the received content before it is displayed. For example, the Netscape browser caches content before receiving a line break or the beginning of an html tag, and receivesThe entire table is not displayed until it is marked.
3. for some versions of Microsoft Internet Explorer, the page is displayed only after 256 bytes are received. Therefore, some extra spaces must be sent for these browsers to display the page content.
Therefore, the correct sequence of use is: first ob_flush, then flush.
Of course, other SAPIs do not call flush, but we recommend that you use it to ensure the portability of your code.

*/

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 section describes how to organize php execution and output data, including related content, and hopes to help those who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.