Static pages are especially important for a website that is not updated frequently. when the website is too large and has a high access volume, the website can be opened too slowly or even cannot be opened.
Static pages are especially important for a website that is not updated frequently. when the website is too large and has a high access volume, the website can be opened too slowly or even cannot be opened, of course, when the user sees that the website cannot be opened, the webpage will be shut down. so I have studied static methods. of course thinkphp also has its own method, so I won't talk about it.
Write in the action of the page to be static
Action method
Ob_start ();
$ Static_file = './home/Tpl/default/Index/s.html'; // static page
$ Path = './IndexAction. class. php ';
$ Php_file = basename ($ path); // The current dynamic page
If (! File_exists ($ static_file) |
(Filemtime ($ static_file) + 1800) <time () | // fixed cache time
Filemtime ($ php_file)> filemtime ($ static_file) // you can determine whether the source file has been modified.
{
// The following is the logic in your own action.
$ User = M ('user ');
$ Tupian = M ('tupianshangchuan ');
$ Tupian = $ tupian-> select ();
$ List = $ user-> where ('email = "'. Session: get ('email'). '"')-> select ();
$ This-> assign ('tupian', $ tupian );
$ This-> assign ('list', $ list );
$ This-> display (s_index );
$ C = ob_get_contents ();
File_put_contents ($ static_file, $ c );
} Else {
$ This-> display ('s ');
}