现在的位置: 首页 > 综合 > 正文

phpcms2008 首页index.php浅析

2018年06月06日 ⁄ 综合 ⁄ 共 2753字 ⁄ 字号 评论关闭

<?php
require dirname(__FILE__).'/include/common.inc.php';   //加载公共函数
$head['title'] = $PHPCMS['sitename'];                 //调用公共变量站名
$head['keywords'] = $PHPCMS['meta_keywords'];         //调用公共变量设置的关键字
$head['description'] = $PHPCMS['meta_description'];    //调用公共变量设置的网站内容描述文字
header('Last-Modified: '.gmdate('D, d M Y H:i:s', TIME).' GMT');      //设置网页在服务器上修改的修改时间
header('Expires: '.gmdate('D, d M Y H:i:s', TIME+CACHE_PAGE_INDEX_TTL).' GMT');  //设置服务器的访问响应超时时间
header('Cache-Control: max-age='.CACHE_PAGE_INDEX_TTL.', must-revalidate');   //设置最在page的cache缓存时间
include template('phpcms', 'index');    //调用模板
cache_page(CACHE_PAGE_INDEX_TTL);       //缓存默认生命周期
?>

//缓存配置如下
define('CACHE_STORAGE', 'files'); //Cache 存储方式(files, mysql, apc, eaccelerator, memcache, shmop)
define('CACHE_PATH', PHPCMS_ROOT.'data/cache/'); //缓存默认存储路径
define('CACHE_MODEL_PATH', PHPCMS_ROOT.'data/cache_model/'); //模型缓存存储路径
//页面缓存配置
define('CACHE_PAGE', 0); //是否开启PHP页面自动缓存功能
define('CACHE_PAGE_PATH', PHPCMS_ROOT.'data/cache_page/'); //缓存存储路径
define('CACHE_PAGE_TTL', 3600); //秒,缓存默认生命周期
define('CACHE_PAGE_INDEX_TTL', 300); //秒,缓存默认生命周期
define('CACHE_PAGE_CATEGORY_TTL', 600); //秒,缓存默认生命周期
define('CACHE_PAGE_LIST_TTL', 900); //秒,缓存默认生命周期
define('CACHE_PAGE_CONTENT_TTL', 14400); //秒,缓存默认生命周期

//所用到的函数

function cache_page($ttl = CACHE_PAGE_TTL, $isjs = 0)
{
if($ttl == 0 || !defined('CACHE_PAGE_FILE')) return false;
$contents = ob_get_contents();          //将ob生成的内容取出来
if($isjs) $contents = format_js($contents);  //判断是否为js,如果为,则格式化写入
dir_create(CACHE_PAGE_DIR);                //创建cahce的目录
$contents = "<!--expiretime:".(TIME + $ttl)."-->/n".$contents;   //设置文件最后的修改时间,以防同样的访问,再次生成cahce
file_put_contents(CACHE_PAGE_FILE, $contents);               //将内容写入,原来生生的cahce_file_name 中 cache file名的生成在          //  cache_page_start()这个函数中
@chmod(CACHE_PAGE_FILE, 0777);                                   //设置cahe目录的可读性,
}

function cache_page_start()
{
define('CACHE_PAGE_ID', md5(RELATE_URL));
define('CACHE_PAGE_DIR', CACHE_PAGE_PATH.substr(CACHE_PAGE_ID, 0, 2).'/');
define('CACHE_PAGE_FILE', CACHE_PAGE_DIR.CACHE_PAGE_ID.'.html');
$contents = @file_get_contents(CACHE_PAGE_FILE);
if($contents && intval(substr($contents, 15, 25)) > TIME)
{
  echo substr($contents, 29);
  exit;
}
return true;
}

function template($module = 'phpcms', $template = 'index', $istag = 0)
{
$compiledtplfile = TPL_CACHEPATH.$module.'_'.$template.'.tpl.php';   //加载我们平时做的模版目录中的数据生成页面,会放置它的引擎变量里以至后面我们加载html代码后,一同跑出来,的页面,这种模式为MVC模式
if(TPL_REFRESH && (!file_exists($compiledtplfile) || @filemtime(TPL_ROOT.TPL_NAME.'/'.$module.'/'.$template.'.html') > @filemtime//加载模版文件hmtl部分,
($compiledtplfile) || @filemtime(TPL_ROOT.TPL_NAME.'/tag.inc.php') > @filemtime($compiledtplfile))) //加载不同栏目的tag,然后成生页面
{
  require_once PHPCMS_ROOT.'include/template.func.php';   
  template_compile($module, $template, $istag);
}
return $compiledtplfile;
}

php CMS所有的模块就是如此结构, 先看是事原来有缓存,无则生成数据,和cahce 然后将数据刷入模板,然后展示出来.....

抱歉!评论已关闭.