ThinkPHP3.2.3学习笔记4---统计ThinkPHP3.2.3加载的文件
将ThinkPHP3.2.3的入口文件index.php加入一个函数getIncludeFiles,文件内容变成如下所示:
1 <?php 2 // +---------------------------------------------------------------------- 3 // | ThinkPHP [ WE CAN DO IT JUST THINK ] 4 // +---------------------------------------------------------------------- 5 // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved. 6 // +---------------------------------------------------------------------- 7 // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) 8 // +---------------------------------------------------------------------- 9 // | Author: liu21st <liu21st@gmail.com> 10 // +---------------------------------------------------------------------- 11 12 // 应用入口文件 13 14 // 检测PHP环境 15 if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); 16 17 // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false 18 define('APP_DEBUG',True); 19 20 // 定义应用目录 21 define('APP_PATH','./Application/'); 22 23 // 引入ThinkPHP入口文件 24 require './ThinkPHP/ThinkPHP.php'; 25 26 // 亲^_^ 后面不需要任何代码了 就是如此简单 27 28 getIncludeFiles(); 29 30 function getIncludeFiles() { 31 $files = get_included_files(); 32 33 $fileCount = count($files); 34 echo "ThinkPHP3.2.3框架共加载{$fileCount}个文件<br />\n"; 35 $i = 0; 36 foreach ($files as $file) { 37 $i++; 38 echo "{$i}、Included file {$file}...<br />\n"; 39 } 40 } 41 ?>
在浏览中访问http://localhost:81/research/thinkphp_3.2.3_full/index.php
输出如下:
ThinkPHP3.2.3框架共加载27个文件
1、Included file E:\myphp\research\thinkphp_3.2.3_full\index.php...
2、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\ThinkPHP.php...
3、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Think.class.php...
4、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Storage.class.php...
5、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Storage\Driver\File.class.php...
6、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Mode\common.php...
7、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Common\functions.php...
8、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Hook.class.php...
9、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\App.class.php...
10、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Dispatcher.class.php...
11、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Route.class.php...
12、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\View.class.php...
13、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Behavior\BuildLiteBehavior.class.php...
14、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Behavior\ParseTemplateBehavior.class.php...
15、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Behavior\ContentReplaceBehavior.class.php...
16、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Conf\convention.php...
17、Included file E:\myphp\research\thinkphp_3.2.3_full\Application\Common\Conf\config.php...
18、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Lang\zh-cn.php...
19、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Conf\debug.php...
20、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Log.class.php...
21、Included file E:\myphp\research\thinkphp_3.2.3_full\Application\Home\Conf\config.php...
22、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Behavior\ReadHtmlCacheBehavior.class.php...
23、Included file E:\myphp\research\thinkphp_3.2.3_full\Application\Home\Controller\IndexController.class.php...
24、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Think\Controller.class.php...
25、Included file E:\myphp\research\thinkphp_3.2.3_full\Application\Runtime\Cache\Home\20914c0f075f91df3579ffbdf5180b02.php...
26、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Behavior\WriteHtmlCacheBehavior.class.php...
27、Included file E:\myphp\research\thinkphp_3.2.3_full\ThinkPHP\Library\Behavior\ShowPageTraceBehavior.class.php...
总结:
只是访问入口文件index.php,没有完成任何功能,就加载了27个文件,如果要调用具体的业务逻辑加载的文件还会更多,而且业务中可能还会调用数据库、NoSQL、文件系统、消息队列等系统,一个请求从开始到结束的时间可能会更长。
对于高并发、高可用、高性能的分布式系统来说,性能显得尤为重要,使用框架可能会提高开发效率,但是对性能可能会有一些影响,所以有些大公司采用自己写的框架或不用框架来开发项目。
延伸阅读:
http://www.baidu.com/s?wd=thinkphp%20性能优化
http://www.sogou.com/web?query=thinkphp%20性能优化
https://www.so.com/s?q=thinkphp%20性能优化
http://www.baidu.com/s?wd=程序%20性能优化
http://www.sogou.com/web?query=程序%20性能优化
https://www.so.com/s?q=程序%20性能优化