当前位置:网站首页>PHP one-time request lifecycle
PHP one-time request lifecycle
2022-07-26 09:47:00 【Color the sky】
original text :http://www.nowamagic.net/librarys/veda/detail/1287
We've never turned it on manually PHP Related processes of , It is coming along with Apache Started by .PHP adopt mod_php5.so Module and Apache Connected to a ( To be specific, it is SAPI, Server application programming interface ).
PHP There are three modules in total : kernel 、Zend engine 、 And the extension layer .
- PHP The kernel is used to process requests 、 File stream 、 Error handling and other related operations ;
- Zend engine (ZE) To convert source files to machine language , Then run it on the virtual machine ;
- The extension layer is a set of functions 、 Class libraries and streams ,PHP Use them to perform specific actions .
such as , We need to mysql Extend to connect MySQL database ; When ZE Several extensions may need to be connected when executing the program , At this time ZE Give control to extension , Return after processing specific tasks ; Last ,ZE Return the result of program running to PHP kernel , It then sends the results to SAPI layer , Final output to browser .
In-depth discussion
The real internal operation process is not so simple . The above process is only a simplified version , Let's dig deeper , Look what happened behind the scenes .
Apache After starting ,PHP The interpreter starts .PHP There are two steps in the startup process of :
- The first step is to initialize some environment variables , This will be throughout SAPI Play a role in the life cycle ;
- The second step is to generate some variable settings only for the current request .
PHP Start the first step
I don't know what the first and second steps are ? Don't worry , Let's discuss it in detail next . Let's take a look at the first step , It is also the most important step . Remember that , The first step occurs before any request arrives .
start-up Apache after ,PHP The interpreter starts .PHP Call the of each extension MINIT Method , To make these extensions available . have a look php.ini What extensions are open in the file . MINIT It means “ Module initialization ”. Each module defines a set of functions 、 Class libraries, etc. to handle other requests .
A typical MINIT The method is as follows :
1 | PHP_MINIT_FUNCTION(extension_name){ /* Initialize functions, classes etc */ } |
PHP Start the second step
When a page request occurs ,SAPI Layer gives control to PHP layer . therefore PHP Set the environment variables required to reply to this request . meanwhile , It also creates a variable table , Used to store the execution process Variable names and values generated in .PHP Call the RINIT Method , namely “ Request initialization ”. A classic example is Session Modular RINIT, If in php.ini in To enable the Session modular , That's calling the RINIT Will be initialized $_SESSION Variable , And read it in ;RINIT Method can be seen as a preparatory process , It starts automatically between program execution . A typical RINIT The method is as follows :
1 | PHP_RINIT_FUNCTION(extension_name) { /* Initialize session variables,pre-populate variables, redefine global variables etc */ } |
PHP Close the first step
Like PHP It's the same as starting ,PHP There are also two steps to close the . Once the page is executed ( Whether it is executed to the end of the file or exit or die Function abort ),PHP Will start the cleanup program . It will call each module's RSHUTDOWN Method . RSHUTDOWN To clear the symbol table generated when the program is running , That is to call for each variable unset function .
A typical RSHUTDOWN The method is as follows :
1 | PHP_RSHUTDOWN_FUNCTION(extension_name) { /* Do memory management, unset all variables used in the last PHP call etc */ } |
PHP Close step 2
Last , All requests have been processed ,SAPI It's ready to close ,PHP Start the second step :PHP Call... For each extension MSHUTDOWN Method , This is the last chance for each module to free memory .
A typical RSHUTDOWN The method is as follows :
1 | PHP_MSHUTDOWN_FUNCTION(extension_name) { /* Free handlers and persistent memory etc */ } |
such , Whole PHP The life cycle is over . It should be noted that , Only if the server has no requests “ Start the first step ” and “ Close step 2 ”.
边栏推荐
猜你喜欢
Customize permission validation in blazor
Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
[Online deadlock analysis] by index_ Deadlock event caused by merge
配置ADCS后访问certsrv的问题
新增市场竞争激烈,中国移动被迫推出限制性超低价5G套餐
R语言ggplot2可视化: 将图例标题(legend title)对齐到ggplot2中图例框的中间(默认左对齐、align legend title to middle of legend)
Sqoop【环境搭建 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
Server and client dual authentication (2)
MQTT X CLI 正式发布:强大易用的 MQTT 5.0 命令行工具
解决npm -v突然失效 无反应
随机推荐
添加dll
配置ADCS后访问certsrv的问题
E. Two Small Strings
面试突击68:为什么 TCP 需要 3 次握手?
The problem of accessing certsrv after configuring ADCs
网络流学习笔记
Node memory overflow and V8 garbage collection mechanism
Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool
spolicy请求案例
【Mysql数据库】mysql基本操作集锦-看得会的基础(增删改查)
E. Two Small Strings
IIS error prompt after installing Serv-U: hresult:0x80070020
Why does new public chain Aptos meet market expectations?
Development to testing: a six-year road to automation starting from 0
R语言ggplot2可视化: 将图例标题(legend title)对齐到ggplot2中图例框的中间(默认左对齐、align legend title to middle of legend)
After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
Audio and video knowledge
The diagram of user login verification process is well written!
Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package
一种分布式深度学习编程新范式:Global Tensor