How to correctly use the PHP function flush () _ PHP Tutorial

Source: Internet
Author: User
Teach you how to use the PHP function flush () correctly (). For the content just learned 1. Flush: refresh the buffer and output. Function format: flush () is a very efficient function in PHP3, which has a very

1. Flush: refresh the buffer content and output it.
Function format: flush ()

This function appears in PHP3. it is a very efficient function. a very useful function is to refresh the browser cache. let's take an example with very obvious running effect to illustrate the PHP function flush ().

Example 2.

 
 
  1. <? Php
  2. For ($ I = 1; $ I <= 300; $ I ++) print ("");
  3. // This sentence is critical, and the cache structure
    So that its content can be output from the browser only when it reaches a certain size
  4. // In other words, if the cache content does not reach
    It is not output before the program is executed. Jing
  5. // After testing, I found that the limit of this size is
    256 characters long. This means that all content received by the cache will be
  6. // Continuously sent out.
  7. For ($ j = 1; $ j <= 20; $ j ++ ){
  8. Echo $ j ."
  9. ";
  10. Flush (); // This part will add content to the cache.
    Squeezed out and displayed on the browser
  11. Sleep (1); // let the program "sleep" for one second, it will
    You can see the effect more clearly.
  12. }
  13. ?>

PHP2000's latest PHP chat room uses this technology. Unfortunately, the source code is not publicly available. Note: If ob_implicit_flush () is added to the program header to enable absolute refresh, you can stop using the PHP function flush () in the program. The advantage of doing so is to improve efficiency!


Tip 1. Flush: refresh the buffer content and output it. Function format: flush () this function appears in PHP3. it is a very efficient function and has a very...

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.