Home >Backend Development >PHP Tutorial >ThinkPHP32 loading process (1)
Loading process (official introduction) :
<span>The user <span>URL<span> requests </span></span></span>
<span>Call the application entry file (usually the website’s <span>index<span>.<span>php<span>)</span></span></span></span></span>
<span>Load the framework entry file ( <span>ThinkPHP<span>.<span>php<span>)</span></span></span></span></span>
<span>Record initial running time and memory overhead</span>
<span>System constant judgment and definition</span>
<span>Load the framework boot class (<span>Think <span>Think<span>) and execute the <span>Think<span>::<span>start<span> method to initialize the application</span></span></span></span></span></span></span></span>
<span>Set the error handling mechanism and automatic loading mechanism</span>
<span>Call <span>Think<span>Storage <span>Class performs storage initialization (the storage type is defined by the <span>STORAGE_TYPE<span>constant)</span></span></span></span></span></span>
<span>In deployment mode, if there is an application compilation cache file, it will be loaded directly (jump directly to step <span>22<span>)</span></span> </span>
<span>Read the definition file of the application mode (defined by the <span>APP_MODE<span> constant) (the following uses normal mode as an example) </span></span></span>
<span>Load the core file defined by the current application mode (normal mode is <span><span>ThinkPHP<span>/<span>Mode<span>/<span>common<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span>
<span>load the custom configuration file (normal mode is <span> <span>ThinkPHP<span>/<span>Conf<span>/<span> convention<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span>
<span>load application configuration file (normal mode is <span><span>Application<span>/<span>Common<span>/<span>Conf<span>/ <span>config<span>.<span>php<span> ) </span></span></span></span></span></span></span></span></span></span></span></span>
<span>Load system alias definition </span>
<span> Judge and read the application alias definition file (normal mode is <span><span>Application <span>/<span>Common<span>/<span> Conf<span>/<span>alias<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>Loading system behavior definition</span>
<span>Judge and read the application behavior definition file (normal mode is <span><span>Application<span>/<span>Common<span>/<span>Conf<span>/<span>tags<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>Load the underlying language package of the framework (normal mode is <span><span>ThinkPHP <span>/<span>Lang<span>/<span>zh<span>-<span>cn<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>If it is deployment mode then Generate application compilation cache file</span>
<span>Load the debug mode system configuration file (<span>ThinkPHP<span>/<span>Conf<span>/<span>debug<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span>
<span>Judge and read the application’s debug configuration file ( The default is <span><span>Application<span>/<span>Common<span>/<span>Conf<span>/<span>debug<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>Determine the application status and read the status configuration file (if <span> APP_STATUS<span>constant definition is not empty)</span></span></span>
<span> detects the application directory structure and automatically generates it (if the <span>CHECK_APP_DIR<span> configuration is turned on and the <span>RUNTIME_PATH<span> directory does not exist)</span></span></span></span></span>
<span> Call the <span>run<span> method of the <span>Think<span>App<span> class to start the application </span></span></span></span></span></span>
<span>The application initialization (<span>app_init<span>) tag bit listens and performs the binding behavior </span></span></span>
<span>Determine and load dynamic configuration and function files</span>
<span>Call the <span>Think<span>Dispatcher<span>::<span>dispatch<span> method to perform <span>URL<span>request dispatch</span></span></span></span></span></span></span></span>
<span>Automatic identification and compatibility<span> The <span>$_SERVER<span>[<span>'PATH_INFO'<span>] parameter under URL<span> mode and command line mode </span></span></span></span></span></span></span>
<span> detects domain name deployment and completes the binding operation of modules and controllers (<span>APP_SUB_DOMAIN_DEPLOY <span> Parameters on) </span></span></span>
<span>Analyze the <span>PATH_INFO<span> information in the <span>URL<span> address</span></span></span></span></span>
<span>Get the requested module information</span>
<span>Detect whether the module exists and allow access </span>
<span>Judge and load module configuration files, alias definitions, behavior definitions and function files</span>
<span>Judge and load the module’s dynamic configuration and function files</span>
<span>Module’s <span>URL<span>Mode judgment</span></span></span>
<span>The module’s route detection (<span>URL_ROUTER_ON<span> is turned on)</span></span></span>
<span>PATH_INFO<span>processing (<span>path_info<span>) tag bit listening and performing binding behavior</span></span></span></span>
<span>URL <span>Suffix detection (<span>URL_DENY_SUFFIX<span> and <span>URL_HTML_SUFFIX<span>handling) </span></span></span></span></span></span>
<span>Get the current controller and action, and <span>URL<span>other parameters</span></span></span>
<span>URL<span>Request scheduling completed (<span>url_dispatch<span>) The tag bit listens and performs binding actions </span></span></span></span>
<span> The application starts (<span>app_begin<span>) The tag bit listens and performs binding actions </span></span></span>
<span>Call <span>SE SSION_OPTIONS <span>Configuration parameters for <span>Session<span> initialization (if not in command line mode) </span></span></span></span></span>
<span>Execute the controller method according to the request</span>
<span>If the controller does not exist, detect whether the empty controller exists</span>
<span>The controller starts (<span>action_begin<span>) tag bit listening and executes the binding behavior</span></span></span>
<span>By default, the system's <span>ReadHtmlCache<span> behavior is called to read the static cache (<span>HTML_CACHE_ON<span>parameter turned on)</span> </span></span></span></span>
<span> Judge and call the <span>_initialize<span> initialization method of the controller </span></span></span>
<span> Judge whether the operation method exists, if not, detect whether the empty operation method is defined </span>
<span> Determine whether the pre-operation method is defined, and if so, perform </span>
<span>Action<span> parameter binding detection to automatically match the parameters of the operation method </span></span>
<span> if there is template rendering (call the controller <span>display<span> method ) </span></span></span>
<span>View start (<span>view_begin<span>) tag bit listens and performs binding behavior</span></span></span>
<span>Call the <span>Think<span>View<span>'s <span>fetch<span> method to parse and get the model Edition content </span> </span></span></span></span></span>
<span> Automatically identify the current theme and locate the template file </span>
<span>View parsing (<span>view_parse<span>) tag bit listens and performs binding actions </span></span></span>
<span>Default call Built-in <span>ParseTemplate<span>behavior analysis template (under normal mode)</span></span></span>
<span>The template engine generates a template cache after parsing the template content</span>
<span>Template filter replacement (<span>template_filter<span>) tag bit listens and executes binding Default behavior </span></span></span>
<span>default calls the system’s <span>ContentReplace<span> behavior for template replacement</span></span></span>
<span>output content filtering (<span>view_filter<span>) tag bit listening and executing binding behavior</span></span> </span>
<span>Default calls the system's <span>WriteHtmlCache<span> behavior to write to the static cache (<span>HTML_CACHE_ON<span> parameter is turned on) </span></span></span></span></span>
<span>Call <span>Think<span>View<span> class <span>r The ender<span> method outputs the rendering content</span></span> </span></span></span></span>
<span>View end (<span>view_end<span>) tag listens and performs binding behavior</span></span></span>
<span>Determine whether the post operation method is defined, and if so, execute it</span>
<span>The controller end (<span>action_end<span>) tag bit listens and executes the binding action </span></span></span>
<span>The application end (<span>app_end<span>) tag bit listens and executes the binding action </span></span></span>
<span> Execute the system's <span>ShowPageTrace<span> behavior (<span>SHOW_PAGE_TRACE<span> parameter is turned on and is not an <span>AJAX<span> request) </span></span></span></span></span></span></span>
<span>Log information storage writing</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 debug mode (in debug mode, when APP_DEBUG is True, the last compiled one is ~runtime.php. In the case of development, it is recommended to start Debug mode)
2. Define the path of APP_PATH
3. It is also the most important one. The entrance to ThinkPHP is introduced. From here, the complex and simple TP framework journey officially begins. Those who do not have the equipment can bring the equipment and brush the TP framework.
I follow the TP source code and introduce how the page appears without making any modifications to the TP
( PS: Since it is my first time to learn the TP framework and also just started to learn PHP, I hope to write a little of my own here. My experience is to sort out my own thoughts. I also hope it can help everyone. If there are any mistakes, I hope you can point them out)
The above introduces the ThinkPHP32 loading process (1), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.