标签:文件的 1.0 zha www. mys 一次函数 mysqli row charset
<?php $filename = "./jingtai.html";//定义一个变量来存放一个缓存文件的路径(相对于当前页面的路径) //定义缓存有效期 $cachetime = 10; //判断缓存文件是否存在 var_dump(filemtime($filename)); //filemtime($filename)不变,time()一直变,filemtime($filename)+10肯定会有小于time()的时候。 if(!file_exists($filename)||filemtime($filename)+$cachetime<time()){//filemtime($filename)获取文件修改时间,加上定义的缓存时间小于当前时间 //开启内存缓存 //filemtime()该文件上次修改内容 //filemtime($filename)第一次出现等于当前时间time();每过10秒走一次函数,filemtime($filename)的值就会改变 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"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <table width="100%" border="1" cellpadding="0" cellspacing="0" > <tr> <td>学号</td> <td>姓名</td> <td>性别</td> <td>生日</td> <td>班级</td> </tr> <?php //造连接对象 $db = new MySQLi("localhost","root","","ceshi"); //写SQL语句 $sql = "select * from student"; //执行 $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> </html> <?php //从内存缓存中获取页面代码 $content = ob_get_contents(); //将获取到的内容存放到缓存文件 file_put_contents($filename,$content); //清掉内存缓存 ob_flush(); echo "#####"; //测试是否调用了缓存文件,缓存文件不输出这句话 } else{ //var_dump(filemtime($filename)); var_dump(time()); include($filename); //如果存在,调用缓存文件 } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0" >
<tr>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>生日</td>
<td>班级</td>
</tr>
<tr>
<td>1</td>
<td>101</td>
<td>王超</td>
<td>男</td>
<td>2000-02-12 00:00:00</td>
</tr><tr>
<td>2</td>
<td>103</td>
<td>陆君</td>
<td>男</td>
<td>1974-06-03 00:00:00</td>
</tr><tr>
<td>3</td>
<td>105</td>
<td>匡明</td>
<td>男</td>
<td>1975-10-02 00:00:00</td>
</tr><tr>
<td>4</td>
<td>107</td>
<td>王丽</td>
<td>女</td>
<td>1976-01-23 00:00:00</td>
</tr><tr>
<td>5</td>
<td>108</td>
<td>曾华</td>
<td>男</td>
<td>1977-09-01 00:00:00</td>
</tr><tr>
<td>6</td>
<td>109</td>
<td>王芳</td>
<td>女</td>
<td>1975-02-10 00:00:00</td>
</tr><tr>
<td>7</td>
<td>110</td>
<td>刘备</td>
<td>男</td>
<td>0000-00-00 00:00:00</td>
</tr><tr>
<td>8</td>
<td>111</td>
<td>孙权1</td>
<td>男</td>
<td>0000-00-00 00:00:00</td>
</tr><tr>
<td>9</td>
<td>112</td>
<td>曹操</td>
<td>男</td>
<td>0000-00-00 00:00:00</td>
</tr><tr>
<td>10</td>
<td>113</td>
<td>刘邦</td>
<td>男</td>
<td>0000-00-00 00:00:00</td>
</tr><tr>
<td>11</td>
<td>114</td>
<td>周瑜</td>
<td>男</td>
<td>0000-00-00 00:00:00</td>
</tr><tr>
<td>17</td>
<td>098</td>
<td>zhangsan32</td>
<td>男</td>
<td>0000-00-00 00:00:00</td>
</tr> </table>
</body>
</html>
标签:文件的 1.0 zha www. mys 一次函数 mysqli row charset
原文地址:https://www.cnblogs.com/sunhao1987/p/9343725.html