找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2517|回复: 1

[特效代码] PHP网站实例分析

[复制链接]
发表于 2013-3-30 10:00:44 | 显示全部楼层 |阅读模式 来自 广东省湛江市
  1. <?php
  2. if(version_compare(PHP_VERSION,'5.0.0','<') ) { //版本小于5.0.0
  3.     die('ThinkPHP 1.* require_once PHP > 5.0 !'); //提示并终止
  4. }
  5. //记录开始运行时间 PHP100注释
  6. $GLOBALS['_beginTime'] = microtime(TRUE);
  7. //全局变量 TRUE表示秒与微秒相加
  8.    
  9. // ThinkPHP系统目录定义
  10. if(!defined('THINK_PATH')) define('THINK_PATH', dirname(__FILE__));
  11. //THINK_PATH的值是:d:www_4000Think_path
  12.    
  13. //dirname(dirname(__FILE__));得到的是文件上一层目录名
  14. //dirname(__FILE__);得到的是文件所在层目录名
  15.    
  16. if(!defined('APP_NAME')) define('APP_NAME', md5(THINK_PATH));
  17. //如果没有常量APP_NAME 将应用程序名加密 (PHP100中文网)
  18.    
  19. if(!defined('APP_PATH')) define('APP_PATH', dirname(THINK_PATH).'/'.APP_NAME);

  20. if(!defined('RUNTIME_PATH')) define('RUNTIME_PATH',APP_PATH.'/Temp/');
  21. //运行时路经
  22.    
  23. if(file_exists(RUNTIME_PATH.'~runtime.php')) {
  24.     // 运行时路径中有此文件,加载框架核心缓存文件
  25.     // 如果有修改核心文件请删除该缓存(PHP100.com)
  26.     require_once RUNTIME_PATH.'~runtime.php';
  27. }else{
  28.     // 加载系统定义文件
  29.     require_once THINK_PATH.'/Common/defines.php';
  30.     // 系统函数库
  31.     require_once THINK_PATH.'/Common/functions.php';
  32.     // 加载编译需要的函数文件
  33.     require_once THINK_PATH.'/Common/runtime.php';
  34.     // 第一次运行检查项目目录结构 如果不存在则自动创建
  35.     if(!file_exists(RUNTIME_PATH)) {
  36.         // 创建项目目录结构
  37.         buildAppDir();
  38.     }
  39.      //加载ThinkPHP基类
  40.     import('Think.Core.Base');

  41.     //加载异常处理类
  42.     import('Think.Exception.ThinkException');

  43.     // 加载日志类
  44.     import('Think.Util.Log');

  45.     //加载Think核心类
  46.     import('Think.Core.App');

  47.     import('Think.Core.Action');

  48.     import('Think.Core.Model');

  49.     import('Think.Core.View');

  50.     // 是否生成核心缓存
  51.     $cache =  ( !defined('CACHE_RUNTIME') || CACHE_RUNTIME == true );
  52.     if($cache) {
  53.         if(defined('STRIP_RUNTIME_SPACE') && STRIP_RUNTIME_SPACE == false ) {
  54.             $fun   =  'file_get_contents';
  55.         }else{
  56.             $fun   =  'php_strip_whitespace';
  57.         }
  58.         // 生成核心文件的缓存 去掉文件空白以减少大小
  59.         $content    =  $fun(THINK_PATH.'/Common/defines.php');
  60.         $content   .=  $fun(THINK_PATH.'/Common/functions.php');
  61.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Core/Base.class.php');
  62.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Exception/ThinkException.class.php');
  63.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Util/Log.class.php');
  64.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Core/App.class.php');
  65.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Core/Action.class.php');
  66.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Core/Model.class.php');
  67.         $content   .=  $fun(THINK_PATH.'/Lib/Think/Core/View.class.php');
  68.     }
  69.     if(version_compare(PHP_VERSION,'5.2.0','<') ) {
  70.         // 加载兼容函数
  71.         require_once THINK_PATH.'/Common/compat.php';
  72.         if($cache) {
  73.             $content .= $fun(THINK_PATH.'/Common/compat.php');
  74.         }
  75.     }
  76.     if($cache) {
  77.         file_put_contents(RUNTIME_PATH.'~runtime.php',$content);//将字符串写入文件
  78.         unset($content);//销毁$content
  79.     }
  80. }
  81. // 记录加载文件时间
  82. $GLOBALS['_loadTime'] = microtime(TRUE);
  83. ?>
复制代码

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

发表于 2014-2-24 23:30:02 | 显示全部楼层 来自 广西桂林市
解释得很详细

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-3 23:32 , Processed in 0.037091 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表