PHP smarty缓存
缓存一个页面
test.php
<?php//定义该页面缓存文件存放的路径 $filename = "../cache/cachetest.html";//定义缓存有效期 $cachetime = 5;//判断缓存文件是否存在 if(!file_exists($filename) || filemtime($filename)+$cachetime<time()) {//开启内存缓存ob_start();include("../init.inc.php");include("../DBDA.php");$db = new DBDA();$sql = "select * from car";$attr = $db->Query($sql);$smarty->assign("car",$attr);$smarty->display("test.html");//从内存缓存中获取页面代码$content = ob_get_contents();//将获取到的内容存放到缓存文件file_put_contents($filename,$content);//清掉内存缓存ob_flush();echo "######################################";} else {include($filename); }
test.html
<body> <h1>汽车信息</h1> <table width="100%" border="1" cellpadding="0" cellspacing="0"><tr><td>代号</td><td>汽车名称</td><td>油耗</td><td>价格</td></tr><{foreach $car as $v}><tr><td><{$v[0]}></td><td><{$v[1]}></td><td><{$v[4]}></td><td><{$v[7]}></td></tr><{/foreach}></table> </body>
分页缓存
testa.php
<?php//取当前页 $p=1; if(!empty($_GET["page"])) {$p = $_GET["page"]; } //定义缓存文件存放路径 $filename = "../cache/cahetesta{$p}.html";//判断 if(!file_exists($filename) || filemtime($filename)+30<time()) {ob_start();include("../init.inc.php");include("../DBDA.php");$db = new DBDA();include("page.class.php");$szs = "select count(*) from car";$zs = $db->StrQuery($szs);$page = new Page($zs,5);$xinxi = $page->fpage();$sql = "select * from car ".$page->limit;$attr = $db->Query($sql);$smarty->assign("car",$attr);$smarty->assign("xinxi",$xinxi);$smarty->display("testa.html");$nr = ob_get_contents();file_put_contents($filename,$nr);ob_flush();echo "################################################"; } else {include($filename); }
testa.heml
<body> <h1>汽车信息</h1> <table width="100%" border="1" cellpadding="0" cellspacing="0"><tr><td>代号</td><td>汽车名称</td><td>油耗</td><td>价格</td></tr><{foreach $car as $v}><tr><td><{$v[0]}></td><td><{$v[1]}></td><td><{$v[4]}></td><td><{$v[7]}></td></tr><{/foreach}></table> <div><{$xinxi}></div> </body>
转载于:https://www.cnblogs.com/yy01/p/5714662.html
PHP smarty缓存相关推荐
- Smarty的配置与高级缓存技术
前言 Smarty 是一个出色的PHP模板引擎,它分离了逻辑代码和user interface. 学习和使用Smarty,没有应用到它的缓存技术是一个很大的损失,它可以将用户最终看到的HMTL文件缓存 ...
- smarty缓存文件里是php,php-smarty模版引擎中的缓存应用
php-smarty模版引擎中的缓存应用 同学们在学习的时候一定要保持足够耐心,才能把知识学好.以下百分网小编整理的php smarty模版引擎中的缓存应用实例代码的介绍,希望对大家有所帮助,更多信息 ...
- Smarty模板的基础
对前后端进行分离 如果要用的话,要从网上把smarty文件下载下来,才能用 smarty的核心是一个类 建一个php文件,写一个类文件 <?php class smarty {public $l ...
- smarty实例教程
一.什么是smarty? smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到 ...
- php模板技术smarty,PHP模板技术Smarty
基本信息 讲师: 高洛峰 时长:60分钟 集数:9 每集定价:20 元 描述: 如果你正在设计一个交互式的网站,你一定会关注两个主要的问题,就是界面美工和应用程序.在大多数的项目组中,开发一个Web程 ...
- PHP——smarty模板(第一天)
smarty.class.php 主要的东西放在类里面 templates 放模板 templates_c 放缓存 类里面 $smarty->assign("author", ...
- Smarty s02
保留变量 方便使用php 不用assign {$smarty} get {$smarty.get.page} session {$smarty.session.user.name} server c ...
- Smarty模板引擎技术二
Smarty模板引擎技术 内建函数 include_php内建函数 作用:载入一个php文件,将载入的文件的内容赋值给一个变量 注意:该内建函数只能在2.0中使用,如果使用的话,必须得实例化Smart ...
- PHP模板引擎Smarty概述
PHPChina资讯:Smarty是由Monte Ohrt和Andrei Zmievski写出的PHP模板引擎.它不同于其他的模板引擎,比如FastTemplate或者patTemplate,其中主要 ...
最新文章
- Rose VS PowerDesigner
- 圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单
- PPC中检查某程序是否运行
- 将一个域下的cookie传到另一个域_单点登录那些事儿(二)同域下的单点登录
- java满天星星代码_满天星空的代码实现
- POJ - 3468 A Simple Problem with Integers(分块)
- pandas清华镜像_一款可以像操作Excel一样玩Pandas的可视化神器来了!
- 数据挖掘在呼叫中心的六大应用点
- ps批量操作图片尺寸(一键执行) - 教程篇
- 代码质量 重构 代码鸡汤
- var,object和dynamic
- QML 圆角进度条实现 圆角剪切
- 虚拟机服务器安装iis报错,Windows2008R2安装iis和iis下搭建web服务器(9.18 第七天)...
- win8 桌面显示计算机图标不见了怎么办,win8开始屏幕桌面图标不见了怎么办
- fydeos 安装linux程序,FydeOS安装教程-电脑系统安装手册
- 全球及中国飞行时间传感器芯片行业研究及十四五规划分析报告
- 函数的递归调用(C++)
- 分治、CDQ分治小结
- 家园系统服务器,梦幻西游手游家园系统外观全面升级
- 物联网卡就是不能打电话的电话卡?
热门文章
- 解决远程桌面无法连接问题
- Q币才是腾讯真正的世界级产品
- 编译内核出现make CONFIG_DEBUG_SECTION_MISMATCH=y错误
- 《爱情公寓2》将播 恶搞宣传片大喊“有种别看”
- 使用alterMIME实现添加message footer功能
- Word 2013无法发布文章到博客园
- AWS开源Firecracker,一种运行多租户容器服务的新虚拟化技术
- 面向对象之数值的悲剧(8月28日会议有感)
- 如何快速的给你的项目添加icon图标
- iOS-UIViewController视图控制器跳转界面的几种常用方法