7.20php File Cache

Source: Internet
Author: User

<?PHP$filename= "./jingtai.html";//define a variable to hold the path to a cached file (relative to the path of the current page)//define the cache validity period    $cachetime= 10; //determine if the cache file exists    Var_dump(Filemtime($filename)); //Filemtime ($filename) does not change, time () always changes, Filemtime ($filename) +10 will certainly have less than the Times ().     if(!file_exists($filename)||Filemtime($filename)+$cachetime< Time()){//filemtime ($filename) Gets the file modification time, plus the defined cache time is less than the current time//Open memory Cache//filemtime () the last modified content of the file Filemtime ($filename) The first occurrence equals the current time (); Once every 10 seconds, the value of Filemtime ($filename) changes .        Var_dump( Time()); Ob_start();?> <! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > PHP//Connecting Objects            $db=NewMysqli ("localhost", "root", "" "," Ceshi "); //Write SQL statements            $sql= "SELECT * FROM Student"; //Execution            $result=$db->query ($sql);  while($attr=$result-Fetch_row ()) {                Echo"<tr> <td>{$attr[0]}</td> <td>{$attr[1]}</td> <td>{$attr[2]}</td> <td>{$attr[3]}</td> <td>{$attr[4]}</td> </tr>"; }?> </table> </body> PHP//get the page code from the in-memory cache        $content=ob_get_contents(); //Store the acquired content in the cache file        file_put_contents($filename,$content); //clear out the memory cache        Ob_flush(); Echo"#####";//test whether the cache file is called and the cache file does not output this sentence    }    Else{         //Var_dump (Filemtime ($filename)); Var_dump (Time ());         include($filename);//if present, call cache file    } ?>
<! DOCTYPE html Public "-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 

7.20php File Cache

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.