


ThinkPHP3.2 loading process (1), thinkphp3.2 loading_PHP tutorial
ThinkPHP3.2 loading process (1), thinkphp3.2 loading
Loading process (official introduction) :
<span class="pun">用户<span class="pln">URL<span class="pun">请求</span></span></span>
<span class="pun">调用应用入口文件(通常是网站的<span class="pln">index<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span>
<span class="pun">载入框架入口文件(<span class="typ">ThinkPHP<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span>
<span class="pun">记录初始运行时间和内存开销</span>
<span class="pun">系统常量判断及定义</span>
<span class="pun">载入框架引导类(<span class="typ">Think<span class="pln">Think<span class="pun">)并执行<span class="typ">Think<span class="pun">::<span class="pln">start<span class="pun">方法进行应用初始化</span></span></span></span></span></span></span></span>
<span class="pun">设置错误处理机制和自动加载机制</span>
<span class="pun">调用<span class="typ">Think<span class="pln">Storage<span class="pun">类进行存储初始化(由<span class="pln">STORAGE_TYPE<span class="pun">常量定义存储类型)</span></span></span></span></span></span>
<span class="pun">部署模式下如果存在应用编译缓存文件则直接加载(直接跳转到步骤<span class="lit">22<span class="pun">)</span></span></span>
<span class="pun">读取应用模式(由<span class="pln">APP_MODE<span class="pun">常量定义)的定义文件(以下以普通模式为例说明)</span></span></span>
<span class="pun">加载当前应用模式定义的核心文件(普通模式是<span class="pln"> <span class="typ">ThinkPHP<span class="pun">/<span class="typ">Mode<span class="pun">/<span class="pln">common<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span>
<span class="pun">加载惯例配置文件(普通模式是<span class="pln"> <span class="typ">ThinkPHP<span class="pun">/<span class="typ">Conf<span class="pun">/<span class="pln">convention<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span>
<span class="pun">加载应用配置文件(普通模式是<span class="pln"> <span class="typ">Application<span class="pun">/<span class="typ">Common<span class="pun">/<span class="typ">Conf<span class="pun">/<span class="pln">config<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pun">加载系统别名定义</span>
<span class="pun">判断并读取应用别名定义文件(普通模式是<span class="pln"> <span class="typ">Application<span class="pun">/<span class="typ">Common<span class="pun">/<span class="typ">Conf<span class="pun">/<span class="kwd">alias<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pun">加载系统行为定义</span>
<span class="pun">判断并读取应用行为定义文件(普通模式是<span class="pln"> <span class="typ">Application<span class="pun">/<span class="typ">Common<span class="pun">/<span class="typ">Conf<span class="pun">/<span class="pln">tags<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pun">加载框架底层语言包(普通模式是<span class="pln"> <span class="typ">ThinkPHP<span class="pun">/<span class="typ">Lang<span class="pun">/<span class="pln">zh<span class="pun">-<span class="pln">cn<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pun">如果是部署模式则生成应用编译缓存文件</span>
<span class="pun">加载调试模式系统配置文件(<span class="typ">ThinkPHP<span class="pun">/<span class="typ">Conf<span class="pun">/<span class="pln">debug<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span>
<span class="pun">判断并读取应用的调试配置文件(默认是<span class="pln"> <span class="typ">Application<span class="pun">/<span class="typ">Common<span class="pun">/<span class="typ">Conf<span class="pun">/<span class="pln">debug<span class="pun">.<span class="pln">php<span class="pun">)</span></span></span></span></span></span></span></span></span></span></span></span>
<span class="pun">判断应用状态并读取状态配置文件(如果<span class="pln">APP_STATUS<span class="pun">常量定义不为空的话)</span></span></span>
<span class="pun">检测应用目录结构并自动生成(如果<span class="pln">CHECK_APP_DIR<span class="pun">配置开启并且<span class="pln">RUNTIME_PATH<span class="pun">目录不存在的情况下)</span></span></span></span></span>
<span class="pun">调用<span class="typ">Think<span class="pln">App<span class="pun">类的<span class="pln">run<span class="pun">方法启动应用</span></span></span></span></span></span>
<span class="pun">应用初始化(<span class="pln">app_init<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">判断并加载动态配置和函数文件</span>
<span class="pun">调用<span class="typ">Think<span class="pln">Dispatcher<span class="pun">::<span class="pln">dispatch<span class="pun">方法进行<span class="pln">URL<span class="pun">请求调度</span></span></span></span></span></span></span></span>
<span class="pun">自动识别兼容<span class="pln">URL<span class="pun">模式和命令行模式下面的<span class="pln">$_SERVER<span class="pun">[<span class="str">'PATH_INFO'<span class="pun">]参数</span></span></span></span></span></span></span>
<span class="pun">检测域名部署以及完成模块和控制器的绑定操作(<span class="pln">APP_SUB_DOMAIN_DEPLOY<span class="pun">参数开启)</span></span></span>
<span class="pun">分析<span class="pln">URL<span class="pun">地址中的<span class="pln">PATH_INFO<span class="pun">信息</span></span></span></span></span>
<span class="pun">获取请求的模块信息</span>
<span class="pun">检测模块是否存在和允许访问</span>
<span class="pun">判断并加载模块配置文件、别名定义、行为定义及函数文件</span>
<span class="pun">判断并加载模块的动态配置和函数文件</span>
<span class="pun">模块的<span class="pln">URL<span class="pun">模式判断</span></span></span>
<span class="pun">模块的路由检测(<span class="pln">URL_ROUTER_ON<span class="pun">开启)</span></span></span>
<span class="pln">PATH_INFO<span class="pun">处理(<span class="pln">path_info<span class="pun">)标签位侦听并执行绑定行为</span></span></span></span>
<span class="pln">URL<span class="pun">后缀检测(<span class="pln">URL_DENY_SUFFIX<span class="pun">以及<span class="pln">URL_HTML_SUFFIX<span class="pun">处理)</span></span></span></span></span></span>
<span class="pun">获取当前控制器和操作,以及<span class="pln">URL<span class="pun">其他参数</span></span></span>
<span class="pln">URL<span class="pun">请求调度完成(<span class="pln">url_dispatch<span class="pun">)标签位侦听并执行绑定行为</span></span></span></span>
<span class="pun">应用开始(<span class="pln">app_begin<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">调用<span class="pln">SESSION_OPTIONS<span class="pun">配置参数进行<span class="typ">Session<span class="pun">初始化(如果不是命令行模式)</span></span></span></span></span>
<span class="pun">根据请求执行控制器方法</span>
<span class="pun">如果控制器不存在则检测空控制器是否存在</span>
<span class="pun">控制器开始(<span class="pln">action_begin<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">默认调用系统的<span class="typ">ReadHtmlCache<span class="pun">行为读取静态缓存(<span class="pln">HTML_CACHE_ON<span class="pun">参数开启)</span></span></span></span></span>
<span class="pun">判断并调用控制器的<span class="pln">_initialize<span class="pun">初始化方法</span></span></span>
<span class="pun">判断操作方法是否存在,如果不存在则检测是否定义空操作方法</span>
<span class="pun">判断前置操作方法是否定义,有的话执行</span>
<span class="typ">Action<span class="pun">参数绑定检测,自动匹配操作方法的参数</span></span>
<span class="pun">如果有模版渲染(调用控制器<span class="pln">display<span class="pun">方法)</span></span></span>
<span class="pun">视图开始(<span class="pln">view_begin<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">调用<span class="typ">Think<span class="pln">View<span class="pun">的<span class="pln">fetch<span class="pun">方法解析并获取模版内容</span></span></span></span></span></span>
<span class="pun">自动识别当前主题以及定位模版文件</span>
<span class="pun">视图解析(<span class="pln">view_parse<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">默认调用内置<span class="typ">ParseTemplate<span class="pun">行为解析模版(普通模式下面)</span></span></span>
<span class="pun">模版引擎解析模版内容后生成模版缓存</span>
<span class="pun">模版过滤替换(<span class="pln">template_filter<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">默认调用系统的<span class="typ">ContentReplace<span class="pun">行为进行模版替换</span></span></span>
<span class="pun">输出内容过滤(<span class="pln">view_filter<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">默认调用系统的<span class="typ">WriteHtmlCache<span class="pun">行为写入静态缓存(<span class="pln">HTML_CACHE_ON<span class="pun">参数开启)</span></span></span></span></span>
<span class="pun">调用<span class="typ">Think<span class="pln">View<span class="pun">类的<span class="pln">render<span class="pun">方法输出渲染内容</span></span></span></span></span></span>
<span class="pun">视图结束(<span class="pln">view_end<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">判断后置操作方法是否定义,有的话执行</span>
<span class="pun">控制器结束(<span class="pln">action_end<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">应用结束(<span class="pln">app_end<span class="pun">)标签位侦听并执行绑定行为</span></span></span>
<span class="pun">执行系统的<span class="typ">ShowPageTrace<span class="pun">行为(<span class="pln">SHOW_PAGE_TRACE<span class="pun">参数开启并且不是<span class="pln">AJAX<span class="pun">请求)</span></span></span></span></span></span></span>
<span class="pun">日志信息存储写入</span>
Code:
1. Entry file (index.php)
// 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false define('APP_DEBUG',True); // 定义应用目录 define('APP_PATH','./Application/'); // 引入ThinkPHP入口文件 require './ThinkPHP/ThinkPHP.php';
Function 1. Set whether it is debugging mode (in debugging mode, that is, when APP_DEBUG is True, the last compiled one ~runtime.php will not be loaded. In the case of development, it is recommended to start debugging mode)
2. Define the path of APP_PATH
3. It is also the most important one. The entrance to ThinkPHP is introduced. From here on, the complex yet simple TP framework journey officially begins. Those who do not have good equipment can bring their equipment and go brush the TP framework.
I will follow the TP source code and introduce how the page appears without making any modifications to the TP
( PS: Since this is my first time to learn TP framework and also just started to learn PHP, I hope to write down some of my own experience here to sort out my own ideas. I also hope to help everyone. If there are any mistakes, I hope everyone can tell me. )

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
![Error loading plugin in Illustrator [Fixed]](https://img.php.cn/upload/article/000/465/014/170831522770626.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
When launching Adobe Illustrator, does a message about an error loading the plug-in pop up? Some Illustrator users have encountered this error when opening the application. The message is followed by a list of problematic plugins. This error message indicates that there is a problem with the installed plug-in, but it may also be caused by other reasons such as a damaged Visual C++ DLL file or a damaged preference file. If you encounter this error, we will guide you in this article to fix the problem, so continue reading below. Error loading plug-in in Illustrator If you receive an "Error loading plug-in" error message when trying to launch Adobe Illustrator, you can use the following: As an administrator

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Subtitles not working on Stremio on your Windows PC? Some Stremio users reported that subtitles were not displayed in the videos. Many users reported encountering an error message that said "Error loading subtitles." Here is the full error message that appears with this error: An error occurred while loading subtitles Failed to load subtitles: This could be a problem with the plugin you are using or your network. As the error message says, it could be your internet connection that is causing the error. So please check your network connection and make sure your internet is working properly. Apart from this, there could be other reasons behind this error, including conflicting subtitles add-on, unsupported subtitles for specific video content, and outdated Stremio app. like

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

If you encounter freezing issues when inserting hyperlinks into Outlook, it may be due to unstable network connections, old Outlook versions, interference from antivirus software, or add-in conflicts. These factors may cause Outlook to fail to handle hyperlink operations properly. Fix Outlook freezes when inserting hyperlinks Use the following fixes to fix Outlook freezes when inserting hyperlinks: Check installed add-ins Update Outlook Temporarily disable your antivirus software and then try creating a new user profile Fix Office apps Program Uninstall and reinstall Office Let’s get started. 1] Check the installed add-ins. It may be that an add-in installed in Outlook is causing the problem.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.
