首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >ThinkPHP8在一次HTTP请求中要加载120+文件?

ThinkPHP8在一次HTTP请求中要加载120+文件?

作者头像
Tinywan
发布2025-05-23 12:51:28
发布2025-05-23 12:51:28
31400
代码可运行
举报
文章被收录于专栏:开源技术小栈开源技术小栈
运行总次数:0
代码可运行

概述

ThinkPHP是一个免费开源的,快速、简单的面向对象的轻量级PHP开发框架,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP诞生十七年来一直秉承简洁实用的设计原则,在保持出色的性能和至简代码的同时,更注重易用性。遵循Apache2开源许可协议发布,意味着你可以免费使用ThinkPHP,甚至允许把你基于ThinkPHP开发的应用开源或商业产品发布/销售。

ThinkPHP8.x基于PHP8.06.1版本进行了重构和优化,并更加规范化,后续版本可能会陆续提升PHP的版本要求。

安装

代码语言:javascript
代码运行次数:0
运行
复制
composer create-project topthink/think tp

这里的tp目录名你可以任意更改,这个目录就是我们后面会经常提到的应用根目录。

开启调试模式

应用默认是部署模式,在开发阶段,可以修改环境变量APP_DEBUG开启调试模式,上线部署后切换到部署模式。

本地开发的时候可以在应用根目录下面定义.env文件。

代码语言:javascript
代码运行次数:0
运行
复制
// 设置开启调试模式
APP_DEBUG =  true

测试运行

现在只需要做最后一步来验证是否正常运行。

代码语言:javascript
代码运行次数:0
运行
复制
php think run

如果你本地80端口没有被占用的话,也可以直接使用-p参数指定端口

代码语言:javascript
代码运行次数:0
运行
复制
php think run -p 8289

浏览器控制台输出

Trace调试功能支持在浏览器的console直接输出,这样可以方便没有页面输出的操作功能调试,只需要在配置文件中设置:

代码语言:javascript
代码运行次数:0
运行
复制
/ 使用浏览器console输出trace信息
'type'  =>  'console',

在浏览器中输入地址

代码语言:javascript
代码运行次数:0
运行
复制
http://127.0.0.1:8289/

控制台基本信息

代码语言:javascript
代码运行次数:0
运行
复制
请求信息 2025-05-23 08:53:06 HTTP/1.1 GET : http://127.0.0.1:8289/
(index):5 运行时间 0.877023s [ 吞吐率:1.14req/s ] 内存消耗:74.30kb 文件加载:106
(index):6 查询信息 0 queries
(index):7 缓存信息 0 reads,0 writes

注意:文件加载 106 个文件

代码语言:javascript
代码运行次数:0
运行
复制
1 /var/www/ThinkPHP/ThinkPHP8.1/public/router.php ( 0.78 KB )
(index):102 /var/www/ThinkPHP/ThinkPHP8.1/public/index.php ( 0.79 KB )
(index):113 /var/www/ThinkPHP/ThinkPHP8.1/vendor/autoload.php ( 0.75 KB )
(index):124 /var/www/ThinkPHP/ThinkPHP8.1/vendor/composer/autoload_real.php ( 1.63 KB )
(index):135 /var/www/ThinkPHP/ThinkPHP8.1/vendor/composer/platform_check.php ( 0.90 KB )
(index):146 /var/www/ThinkPHP/ThinkPHP8.1/vendor/composer/ClassLoader.php ( 15.99 KB )
(index):157 /var/www/ThinkPHP/ThinkPHP8.1/vendor/composer/autoload_static.php ( 4.07 KB )
(index):168 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
(index):179 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/helper.php ( 1.46 KB )
(index):1810 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
(index):1911 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
(index):2012 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Facade.php ( 2.71 KB )
(index):2113 /var/www/ThinkPHP/ThinkPHP8.1/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
(index):2214 /var/www/ThinkPHP/ThinkPHP8.1/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.77 KB )
(index):2315 /var/www/ThinkPHP/ThinkPHP8.1/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.60 KB )
(index):2416 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/App.php ( 15.00 KB )
(index):2517 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Container.php ( 15.45 KB )
(index):2618 /var/www/ThinkPHP/ThinkPHP8.1/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
(index):2719 /var/www/ThinkPHP/ThinkPHP8.1/app/provider.php ( 0.19 KB )
(index):2820 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
(index):2921 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
(index):3022 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
(index):3123 /var/www/ThinkPHP/ThinkPHP8.1/app/common.php ( 0.03 KB )
(index):3224 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/helper.php ( 18.47 KB )
(index):3325 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
(index):3426 /var/www/ThinkPHP/ThinkPHP8.1/config/app.php ( 0.95 KB )
(index):3527 /var/www/ThinkPHP/ThinkPHP8.1/config/cache.php ( 0.78 KB )
(index):3628 /var/www/ThinkPHP/ThinkPHP8.1/config/console.php ( 0.23 KB )
(index):3729 /var/www/ThinkPHP/ThinkPHP8.1/config/cookie.php ( 0.56 KB )
(index):3830 /var/www/ThinkPHP/ThinkPHP8.1/config/database.php ( 2.15 KB )
(index):3931 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
(index):4032 /var/www/ThinkPHP/ThinkPHP8.1/config/filesystem.php ( 0.61 KB )
(index):4133 /var/www/ThinkPHP/ThinkPHP8.1/config/lang.php ( 0.81 KB )
(index):4234 /var/www/ThinkPHP/ThinkPHP8.1/config/log.php ( 1.35 KB )
(index):4335 /var/www/ThinkPHP/ThinkPHP8.1/config/middleware.php ( 0.19 KB )
(index):4436 /var/www/ThinkPHP/ThinkPHP8.1/config/route.php ( 1.75 KB )
(index):4537 /var/www/ThinkPHP/ThinkPHP8.1/config/session.php ( 0.57 KB )
(index):4638 /var/www/ThinkPHP/ThinkPHP8.1/config/trace.php ( 0.34 KB )
(index):4739 /var/www/ThinkPHP/ThinkPHP8.1/config/view.php ( 0.82 KB )
(index):4840 /var/www/ThinkPHP/ThinkPHP8.1/app/event.php ( 0.25 KB )
(index):4941 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Event.php ( 7.58 KB )
(index):5042 /var/www/ThinkPHP/ThinkPHP8.1/app/service.php ( 0.13 KB )
(index):5143 /var/www/ThinkPHP/ThinkPHP8.1/app/AppService.php ( 0.26 KB )
(index):5244 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
(index):5345 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Lang.php ( 7.24 KB )
(index):5446 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
(index):5547 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
(index):5648 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
(index):5749 /var/www/ThinkPHP/ThinkPHP8.1/vendor/services.php ( 0.14 KB )
(index):5850 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
(index):5951 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
(index):6052 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/service/ModelService.php ( 1.75 KB )
(index):6153 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
(index):6254 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
(index):6355 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
(index):6456 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
(index):6557 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Validate.php ( 53.49 KB )
(index):6658 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/Model.php ( 23.61 KB )
(index):6759 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 19.75 KB )
(index):6860 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.05 KB )
(index):6961 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.01 KB )
(index):7062 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.59 KB )
(index):7163 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
(index):7264 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.26 KB )
(index):7365 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
(index):7466 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
(index):7567 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
(index):7668 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
(index):7769 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-orm/src/DbManager.php ( 8.37 KB )
(index):7870 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
(index):7971 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
(index):8072 /var/www/ThinkPHP/ThinkPHP8.1/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
(index):8173 /var/www/ThinkPHP/ThinkPHP8.1/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
(index):8274 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
(index):8375 /var/www/ThinkPHP/ThinkPHP8.1/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
(index):8476 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
(index):8577 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
(index):8678 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
(index):8779 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
(index):8880 /var/www/ThinkPHP/ThinkPHP8.1/app/Request.php ( 0.09 KB )
(index):8981 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Request.php ( 55.72 KB )
(index):9082 /var/www/ThinkPHP/ThinkPHP8.1/app/middleware.php ( 0.26 KB )
(index):9183 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
(index):9284 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-trace/src/TraceDebug.php ( 2.94 KB )
(index):9385 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Route.php ( 23.56 KB )
(index):9486 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/RuleName.php ( 5.34 KB )
(index):9587 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/Domain.php ( 1.25 KB )
(index):9688 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/RuleGroup.php ( 19.91 KB )
(index):9789 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/Rule.php ( 26.26 KB )
(index):9890 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
(index):9991 /var/www/ThinkPHP/ThinkPHP8.1/route/app.php ( 0.71 KB )
(index):10092 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/facade/Route.php ( 4.68 KB )
(index):10193 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 3.75 KB )
(index):10294 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.54 KB )
(index):10395 /var/www/ThinkPHP/ThinkPHP8.1/app/controller/Index.php ( 0.44 KB )
(index):10496 /var/www/ThinkPHP/ThinkPHP8.1/app/BaseController.php ( 2.05 KB )
(index):10597 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/facade/App.php ( 2.73 KB )
(index):10698 /var/www/ThinkPHP/ThinkPHP8.1/vendor/composer/InstalledVersions.php ( 15.76 KB )
(index):10799 /var/www/ThinkPHP/ThinkPHP8.1/vendor/composer/installed.php ( 6.10 KB )
(index):108100 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Response.php ( 8.65 KB )
(index):109101 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/response/Html.php ( 0.97 KB )
(index):110102 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/Cookie.php ( 6.07 KB )
(index):111103 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/think-trace/src/Console.php ( 6.29 KB )
(index):112104 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/log/driver/File.php ( 6.19 KB )
(index):113105 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
(index):114106 /var/www/ThinkPHP/ThinkPHP8.1/vendor/topthink/framework/src/think/log/Channel.php ( 3.88 KB )

整体流程

TP8 的文件加载遵循 “入口引导 → 核心初始化 → 服务注册 → 路由调度 → 控制器执行” 的主线,核心流程涉及以下阶段:

  1. 入口文件触发public/index.php
  2. Composer 自动加载(依赖库初始化)
  3. 框架核心启动think\App初始化)
  4. 服务提供者注册(系统服务与自定义服务)
  5. 配置与环境加载(读取配置文件、环境变量)
  6. 路由解析与调度(匹配请求路由,确定执行控制器)
  7. 执行控制器 / 视图(调用业务逻辑,生成响应)
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-05-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 开源技术小栈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
  • 安装
  • 开启调试模式
  • 测试运行
  • 浏览器控制台输出
    • 控制台基本信息
  • 整体流程
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档