PHP true static cache ob system function PHP function return value PHP array php date Letter

Source: Internet
Author: User
True static caching: (really generates an HTML page that calls the HTML directly in the next operation)
The first time (refresh the Web page) to determine if there is a cache file (can be set one time)
If there is no first time is (can be based on PDO) connection database lookup data output to a page and simultaneously cache (write) to a local. html file;
Once again (refresh the Web page) to determine if the cache file is stored
When a cache file exists, a direct lookup of the local cache (file_get_content) is read out

The following code is written in the CI framework

   $time  =  ten ; //Set Cache page Expiration Time   if  (!is_file ( "obtest.html" ) | | time ()-filemtime ( "obtest.html" );  $time )       {Ob_start (); //Open buffer   $arr  [ Res ' ]=  $this ->db->get ( ' user ' )->result_array ();  $this ->load->view ( ' welcome_message ' ,  $arr ); //print_r ($arr);         $info  = ob_get_contents (); //Get the contents of the buffer and assign a value to $info    $file  =  fopen  ( ' obtest.html ' ,  ' W ' ); //Open file Info.txt   fwrite        ( $file ,  $info ); //write information to Info.txt   fclose           ( $file ); //Close file Info.txt }  Else     {echo  "cache:" ; Echo file_get_contents ( "obtest.html" );}  

Use of the fopen and Filemtime methods:

fopen() 函数打开文件或者 URL。fopen(文件名称,文件访问类型)w写入方式打开。filemtime() 函数返回文件内容上次的修改时间,里面跟文件名。

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP true static cache OB system functions, including PHP, functional aspects, I hope that the PHP tutorial interested in a friend to help.

  • 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.