2. Caching mechanisms

Source: Internet
Author: User

<?phpecho ‘hello100‘;header(‘content-type:text/html;charset=utf-8‘);echo ‘hello200‘;




Solution:

1.把heander()信息放在头部2.打开 ob 缓冲

How to open the OB cache:

1.在 php.ini 中打开2. ob_start()

ob1.php

<?php  //open OB cache  ob_start (); echo   ' hello100 ' ; header ( content-type:text/html;charset= Utf-8 ' ); echo   ' hello200 ' ; echo   ' hello300 ' ; //gets the data of the OB cache   $str  = Ob_get_contents (); //save $str to File  file_put_contents (, Span class= "hljs-variable" > $str ); echo   ' hello400 ' ; echo   ' hello500 ' ; echo   ' hello600 ' ;  

Wjh.log

hello100hello200hello300

several principles:

Situation cache:

<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';Echo ' hello300 ';//Empty OB cacheOb_clean ();//Get OB-Cached data$str= Ob_get_contents ();//Save the $STR to a fileFile_put_contents (' Wjh.log ',$str);Echo ' hello400 ';Echo ' hello500 ';Echo ' hello600 ';

<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';Echo ' hello300 ';//Empty OB cache//ob_clean ();//The function is to empty the data in the OB and close the OB cacheOb_end_clean ();Echo ' hello400 ';//Get OB-Cached data$str= Ob_get_contents ();//Save the $STR to a fileFile_put_contents (' Wjh.log ',$str);Echo ' hello500 ';Echo ' hello600 ';

<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';Echo ' hello300 ';//Empty OB cache//ob_clean ();//The function is to empty the data in the OB and close the OB cache//ob_end_clean ();Ob_clean ();Echo ' hello400 ';//Get OB-Cached data$str= Ob_get_contents ();//Save the $STR to a fileFile_put_contents (' Wjh.log ',$str);Echo ' hello500 ';Echo ' hello600 ';

<?php//开启ob缓存ob_start();echo‘hello100‘;header(‘content-type:text/html;charset=utf-8‘);echo‘hello200‘;//把 ob 缓存的数据,刷新到程序缓存 ,并关闭echo‘hello300‘;$str = ob_get_contents();file_put_contents(‘wjh.log‘,$str//所以文件为空echo‘hello500‘;echo‘hello600‘;

<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';//Put the OB cache data, flush it to the program cache, and close//ob_end_flush ();//Set OB cache data, flush to program cache, do not closeOb_flush ();Echo ' hello300 ';$str= Ob_get_contents (); File_put_contents (' Wjh.log ',$str);//So the file is emptyEcho ' hello500 ';Echo ' hello600 ';

2. Caching mechanisms

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.