Deeply understand the difference between ob_flush and flush in php

WBOY
Release: 2016-07-25 08:58:56
Original
915 people have browsed it
  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) ""



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!