You should be in this position. Learn PHP (3)

Source: Internet
Author: User

1, Ob_start ()

Turn on file caching

2, Ob_get_contents ()

Get the memory in the cache

3, Ob_get_length ()

Get the length of the buffer zone

4, Ob_flush ()

The contents of the output buffer, if you want to get the contents of the buffer to use ob_get_contents () before this function, otherwise the data will be emptied

5, Ob_end_flush ()

Output buffers and close cache

6, Ob_end_clean ()

Clears the cache and closes the output buffer, if this function is not executed after the Ob_start () is opened, the buffer will be written

Let's write a static example of the page to practice practiced hand, this case is based on the thinkphp framework to explain, other framework of the small partners of their own brain repair!

1, first there are four functions

Ob_start () Turn on caching

Ob_get_contents () Gets the contents of the buffer

Ob_clean () Delete the contents of the buffer

Ob_get_clean () gets and then deletes the buffer contents first

2. Then we define a function to generate the static file

/**定义一个缓存文件* @author crazy* @time 2018-03-14*/public function createCache(){$action = ACTION_NAME;$c_name = CONTROLLER_NAME;$dir = ‘./Cache/‘.$c_name.‘/‘.$action.‘/‘;if(is_dir($dir)){file_put_contents("$dir$action".‘.shtml‘,ob_get_contents());}else{if(mkdir($dir,0777,true)){file_put_contents("$dir$action".‘.shtml‘,ob_get_contents());}}}

3, according to the file directory exists and then we do the corresponding redirect

$action = ACTION_NAME;$c_name = CONTROLLER_NAME;$dir = ‘./Cache/‘.$c_name.‘/‘.$action.‘/‘.$action.‘.shtml‘;if(file_exists($dir)){header("Location:http://localhost/simengphp/$dir");}

4, local static

$.ajax({url:‘‘,type:‘get‘,dataType:‘json‘,error: function () {},success:function(data){$.each(data.result,function(key,val){})}});

We write this Ajax method of getting the page content in our template, and then when we call this page, this method automatically creates the

You should be in this position. Learn PHP (3)

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.