<?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