If the company uses the TP framework, then as a newcomer in the first will be asked to understand TP system running process, this article is intended to help new children's shoes quickly understand the TP system process. The process description is given in accordance with the TP manual (the serial number is also the same for easy viewing):
1. User URL request, 2. Invoke the Application portal file (index.php for example)
Most websites use URL rewriting to hide index.php, here's how to check the TP manual. First execute the index.php,
1 //Application Portal File2 3 //Detect PHP environment4 if(Version_compare(php_version, ' 5.3.0 ', ' < ') die(' Require PHP > 5.3.0! '));5 6 //Open Debug mode suggest the development phase to open the deployment phase comment or set to False7 Define(' App_debug ',True);8 9 //defining the App catalogTen Define(' App_path ', './application/')); One A //Introducing the thinkphp entry file - require'./thinkphp/thinkphp.php ';
First determine whether the PHP version is 5.3, 0, and then turn on Debug mode (the following process will explain), when defining the path TP default is the relative path, but the use of absolute paths will speed up the run. The method used on the TP manual is:
The Realpath () method obtains an absolute path, where a method GETCWD () is recommended, and finally enters the thinkphp.php in the core package; Note: The entire site Process execution address is on the site root index.php, not because the process into other controllers and methods to think that the execution of the address also changed, this is a misunderstanding of the novice learning process.
3. Loading the framework entry file (thinkphp.php) 4. Record initial run time and memory overhead 5. System Constants and definitions
Many constants are defined when the thinkphp.php enters and cannot be redefined if the constants have already been defined in the index.php. It is important to note that the following code:
1 if (! defined (' __root__ ')) {2 $_root = rtrim(dirname(_php_file_), '/'); 3 Define (' __root__ ', (($_root$_root= = ' \ \ ') ":$_root)); 4 }
Here is because when we use the site root directory absolute address, if we are local files, so the root directory form of '/xxx ', but after the project on-line address is '/', then the problem arises, '/xxx ' after the address is to write a '/', and '/' Later if you write a '/' repeat, in order to avoid the line and the path between the local conflict, there is a replacement, when the $_root is '/', the direct replacement is empty, so that it can be directly connected with the local '/'.
1 // load core Think class 2 require Core_path. ' Think '. EXT; 3 // 4 think\think::start ();
Next, execute the Start method in Think.class.php under Tp3.2\thinkphp\library\think.
6. Load the Framework Boot class (Think\think) and execute the Think::start method to initialize the application,----(7-23)
First, register the AutoLoad method, set the error and exception handling, and initialize the file storage method (which is not known in detail for the moment). Then there is the point, precompiled file:
1 //[Extra Comment] Define precompiled file name (starting with Application mode, default is common)2 $runtimefile= Runtime_path. App_mode. ' ~runtime.php ';3 if(! App_debug && Storage::has ($runtimefile)){4 //[Extra note] If debug mode is off and the precompiled file exists, load5Storage::load ($runtimefile);6}Else{7 //[Extra note] If the debug mode is open and the precompiled file exists, delete;8 if(Storage::has ($runtimefile))9Storage::unlink($runtimefile);Ten //[Extra Comment] Initialize precompiled parameters $content One $content= ' '; A //Read Application Mode - //[Additional notes] The first step---read the app configuration file, which defaults to thinkphp/mode/common.php - $mode=include Is_file(Conf_path. ' Core.php ')? Conf_path. ' core.php ': Mode_path. App_mode. '. Php; the //Loading core Files - //[Extra Comment]---common.php as a two-dimensional array, start traversing (functions and class files) - foreach($mode[' Core '] as $file){ - if(Is_file($file)) { + //[Extra Comment] loading functions and class files - include $file; + //[Additional notes]---get the contents of the file and save it to $content A if(! App_debug)$content. = Compile ($file); at } - } - - //loading the application mode configuration file - //[Additional annotations]load_config determine the different types of profiles and return their contents - //[Additional Notes] configuration file first load, custom profile convention.php and app profile config.php in //[Extra Note] If $file is an associative array, use the original key value - //[Extra Comment] Call C function, incoming array is initialized, so $_config update to //[Extra Comment] reading a precompiled file skips this step, so modifying these 2 configuration files in deployment mode does not work + foreach($mode[' Config '] as $key=$file){ - Is_numeric($key)? C (Load_config ($file)): C ($key, Load_config ($file)); the } * $ //read the corresponding configuration file for the current application ModePanax Notoginseng //[Additional Comments] Profile read application configuration, non-common application mode valid, read config_xxx.php - if(' common '! = App_mode &&Is_file(Conf_path. ' Config_ '. App_mode.conf_ext)) theC (Load_config (Conf_path. ') Config_ '. App_mode.conf_ext)); + A //load mode alias definition the //[Additional comments] Official alias definition load, map array update to $_map + //[Extra Note]addmap () updates the value of $_map in the class, which is an array that is updated directly, not an array, and is updated $_map - if(isset($mode[' Alias '])){ $Self::addmap (Is_array($mode[' Alias '])?$mode[' Alias ']:include $mode[' Alias ']); $ } - - //load App alias definition file the //[Additional comments] Custom alias definition load, map array update to $_map - if(Is_file(Conf_path. ' Alias.php '))WuyiSelf::addmap (includeConf_path. ' Alias.php '); the - //load mode behavior definition Wu //[Additional comments] Official default behavior tag binding array loading - //[Additional comments] Only 1 parameters for the merge import, 2 parameters for overwrite import (manual is explained) About //[Additional annotations $_tags in the]hook class have been updated $ if(isset($mode[' Tags '])) { -Hook::import (Is_array($mode[' Tags ']?$mode[' Tags ']:include $mode[' Tags ']); - } - A //load app behavior definition + //[Extra Comment] Custom behavior tag binding array loading the //[Additional annotations $_tags in the]hook class have been updated - if(Is_file(Conf_path. ' Tags.php ')) $ //allow apps to add development mode configuration Definitions theHook::import (includeConf_path. ' Tags.php '); the the //loading the framework's underlying language pack the //[Additional Annotations]l method loading Framework Language Pack $_lang has been updated -LincludeThink_path. ' lang/'.Strtolower(C (' Default_lang ')). Php); in the //[Extra Comment] Base loading complete, start generating precompiled files the if(!app_debug) { About //[Extra note] If debug mode is off the //[Additional comments] in the precompiled file, integrate the configuration parameters again the $content. = "\nnamespace {think\\think::addmap (".Var_export(Self::$_map,true).");"; the //[Extra Comment] precompiled file, integration of language parameters, configuration parameters, behavior binding parameters + $content. = "\nl (".Var_export(L (),true).");\ NC (".Var_export(C (),true).‘); Think\hook::import ('.Var_export(Hook::get (),true).‘);}‘; - //[Additional Notes] Import content into precompiled files theStorage::p ut ($runtimefile, Strip_whitespace (' <?php '.$content));Bayi}Else{ the //Debug mode load system default configuration file the //[Additional notes] If debug mode is on, additional configuration files need to be loaded debug.php -CincludeThink_path. ' Conf/debug.php '); - //read the application Debug configuration file the //[Extra Note] If debug.php exists, read the if(Is_file(Conf_path. ' Debug '.conf_ext)) theCincludeConf_path. ' Debug '.conf_ext); the } -}
The code is long and the extra annotations are integrated into the code. First of all, if debug mode is turned off (no precompiled file is generated when debug mode is turned on) and the file exists, the file is loaded directly, and subsequent judgments are not executed.
Summary: The precompiled file contains the following: core,2 in 1.common.php. Partial configuration files, 3. Mappings, 4. Behavior, 5. Language
To be Continued ...
Thinkphp3.2 Beginner's system operation Flow 1