Home >Backend Development >PHP Tutorial >Deeply understand the difference between ob_flush and flush in php

Deeply understand the difference between ob_flush and flush in php

WBOY
WBOYOriginal
2016-07-25 08:58:56992browse
  1. ob_start();
  2. echo '1';
  3. ob_flush();//Output the php cache and refresh it
  4. echo '2';
  5. ob_flush();//Output the php cache and refresh it
  6. $cc = ob_get_contents();
  7. ob_end_clean();
  8. var_dump($cc);
  9. ?>
Copy code

output: 12string(0) ""

Test 2:

  1. ob_start();
  2. echo '1';
  3. flush(); //Output apache cache and refresh it
  4. echo '2';
  5. flush(); //Output apache cache and Refresh
  6. $cc = ob_get_contents();
  7. ob_end_clean();
  8. var_dump($cc);
  9. ?>
Copy code

output: string(2) "12"

Test 3:

  1. ob_start();
  2. echo '1';
  3. ob_flush();//Output php cache and refresh
  4. flush();//Output apache cache and refresh
  5. echo '2' ;
  6. ob_flush();//Output php cache and refresh
  7. flush(); //Output apache cache and refresh
  8. $cc = ob_get_contents();
  9. ob_end_clean();
  10. var_dump($cc);
  11. ?>
Copy code

Output: 12string(0) ""

Test 4,

  1. ob_start();
  2. echo '1';
  3. flush();//Output apache cache and refresh
  4. ob_flush();//Output php cache and refresh
  5. echo '2' ;
  6. flush();//Output apache cache and refresh
  7. ob_flush(); //Output php cache and refresh
  8. $cc = ob_get_contents();
  9. ob_end_clean();
  10. var_dump($cc);
  11. ?>
Copy code

Output: 12string(0) ""



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn