Chinaunix

标题: PHP 缓存技术 [打印本页]

作者: chenqiubite    时间: 2007-07-24 16:10
标题: PHP 缓存技术
PHP PEAR::Cache_Lite 实现页面缓存

附上源代码包:(加入从数据库读取数据操作)


文件:
Cache.tar.gz
大小:
24KB
下载:
下载
简单说明:(修改过的bench.php文件)
?php
// Bench script of Cache_Lite
// $Id: bench.php,v 1.6 2002/09/28 18:05:29 fab Exp $
require_once('../Lite.php');
$options = array(
    'caching' => true,
    'cacheDir' => '/tmp/',
    'lifeTime' => 60 //缓存时间,可以试试改变大小看效果(同时更新数据库数据)
);
$Cache_Lite = new Cache_Lite($options);
if ($data = $Cache_Lite->get('123')) {
    echo($data);
} else {
    // 连接数据库
    $dbh = @mysql_connect("localhost","sys","sys");
    $query = "SELECT * FROM test.test LIMIT 0 , 30 ";
    $res = @mysql_query($query, $dbh);
    $row = mysql_fetch_row( $res );
    $data = '';
    $data = $row[0];
    //原代码保留
    /*for($i=0;$i
    echo($data);
    $Cache_Lite->save($data); //保存数据到相应的目录文件下
}
?>



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30002/showart_345831.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2