时间:2021-07-01 10:21:17 帮助过:21人阅读
//首先查看缓存文件
if(file_exists("static.html")){
//缓存时间为3分钟
if(time()-filemtime("static.html")<60*3){
//将静态文件内容返回给客户端
$start_time = microtime();
echo "我是从静态文件中读取的数据:"."
";
echo file_get_contents("static.html");
$end_time = microtime();
echo "静态文件使用时间:".($end_time-$start_time);
exit;
}
}
//如果是首次访问,或者是上次缓存的时间超过3分钟,则从数据库中读取数据
$host = "127.0.0.1";
$user = "root";
$password = "123456";
//记录开始时间
$start_time = microtime();
mysql_connect($host,$user,$password);
mysql_select_db("mydb");
mysql_query("set names utf8");
$sql = "SELECT name,address,email FROM users";
$resource = mysql_query($sql);
echo "我是从数据库中读取的数据:
";
ob_start();//打开输出缓冲
echo "| 姓名 | 地址 | |
|---|---|---|
| ".$userInfo['name']." | "; echo "".$userInfo['address']." | "; echo "".$userInfo['email']." | "; echo "