Home  >  Article  >  Backend Development  >  ThinkPHP32 loading process (1)

ThinkPHP32 loading process (1)

WBOY
WBOYOriginal
2016-08-08 09:23:34944browse

Loading process (official introduction) :

  1. <span>The user <span>URL<span> requests </span></span></span>
  2. <span>Call the application entry file (usually the website’s <span>index<span>.<span>php<span>)</span></span></span></span></span>
  3. <span>Load the framework entry file ( <span>ThinkPHP<span>.<span>php<span>)</span></span></span></span></span>
  4. <span>Record initial running time and memory overhead</span>
  5. <span>System constant judgment and definition</span>
  6. <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>
  7. <span>Set the error handling mechanism and automatic loading mechanism</span>
  8. <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>
  9. <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>
  10. <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>
  11. <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>
  12. <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>
  13. <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>
  14. <span>Load system alias definition </span>
  15. <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>
  16. <span>Loading system behavior definition</span>
  17. <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>
  18. <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>
  19. <span>If it is deployment mode then Generate application compilation cache file</span>
  20. <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>
  21. <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>
  22. <span>Determine the application status and read the status configuration file (if <span> APP_STATUS<span>constant definition is not empty)</span></span></span>
  23. <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>
  24. <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>
  25. <span>The application initialization (<span>app_init<span>) tag bit listens and performs the binding behavior </span></span></span>
  26. <span>Determine and load dynamic configuration and function files</span>
  27. <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>
  28. <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>
  29. <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>
  30. <span>Analyze the <span>PATH_INFO<span> information in the <span>URL<span> address</span></span></span></span></span>
  31. <span>Get the requested module information</span>
  32. <span>Detect whether the module exists and allow access </span>
  33. <span>Judge and load module configuration files, alias definitions, behavior definitions and function files</span>
  34. <span>Judge and load the module’s dynamic configuration and function files</span>
  35. <span>Module’s <span>URL<span>Mode judgment</span></span></span>
  36. <span>The module’s route detection (<span>URL_ROUTER_ON<span> is turned on)</span></span></span>
  37. <span>PATH_INFO<span>processing (<span>path_info<span>) tag bit listening and performing binding behavior</span></span></span></span>
  38. <span>URL <span>Suffix detection (<span>URL_DENY_SUFFIX<span> and <span>URL_HTML_SUFFIX<span>handling) </span></span></span></span></span></span>
  39. <span>Get the current controller and action, and <span>URL<span>other parameters</span></span></span>
  40. <span>URL<span>Request scheduling completed (<span>url_dispatch<span>) The tag bit listens and performs binding actions </span></span></span></span>
  41. <span> The application starts (<span>app_begin<span>) The tag bit listens and performs binding actions </span></span></span>
  42. <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>
  43. <span>Execute the controller method according to the request</span>
  44. <span>If the controller does not exist, detect whether the empty controller exists</span>
  45. <span>The controller starts (<span>action_begin<span>) tag bit listening and executes the binding behavior</span></span></span>
  46. <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>
  47. <span> Judge and call the <span>_initialize<span> initialization method of the controller </span></span></span>
  48. <span> Judge whether the operation method exists, if not, detect whether the empty operation method is defined </span>
  49. <span> Determine whether the pre-operation method is defined, and if so, perform </span>
  50. <span>Action<span> parameter binding detection to automatically match the parameters of the operation method </span></span>
  51. <span> if there is template rendering (call the controller <span>display<span> method ) </span></span></span>
  52. <span>View start (<span>view_begin<span>) tag bit listens and performs binding behavior</span></span></span>
  53. <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>
  54. <span> Automatically identify the current theme and locate the template file </span>
  55. <span>View parsing (<span>view_parse<span>) tag bit listens and performs binding actions </span></span></span>
  56. <span>Default call Built-in <span>ParseTemplate<span>behavior analysis template (under normal mode)</span></span></span>
  57. <span>The template engine generates a template cache after parsing the template content</span>
  58. <span>Template filter replacement (<span>template_filter<span>) tag bit listens and executes binding Default behavior </span></span></span>
  59. <span>default calls the system’s <span>ContentReplace<span> behavior for template replacement</span></span></span>
  60. <span>output content filtering (<span>view_filter<span>) tag bit listening and executing binding behavior</span></span> </span>
  61. <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>
  62. <span>Call <span>Think<span>View<span> class <span>r The ender<span> method outputs the rendering content</span></span> </span></span></span></span>
  63. <span>View end (<span>view_end<span>) tag listens and performs binding behavior</span></span></span>
  64. <span>Determine whether the post operation method is defined, and if so, execute it</span>
  65. <span>The controller end (<span>action_end<span>) tag bit listens and executes the binding action </span></span></span>
  66. <span>The application end (<span>app_end<span>) tag bit listens and executes the binding action </span></span></span>
  67. <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>
  68. <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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn