当前位置:网站首页>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 ”.
边栏推荐
- JS 一行代码 获取数组最大值与最小值
- 青少年软件编程等级考试标准解读_二级
- Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
- IIS网站配置
- JS table auto cycle scrolling, mouse move in pause
- [fluorescent character effect]
- 电机转速模糊pid控制
- Search module use case writing
- (一)面扫描仪与机械臂的手眼标定(眼在手上)
- [MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)
猜你喜欢
![[Online deadlock analysis] by index_ Deadlock event caused by merge](/img/67/0a02ad248c3ab21d3240e12aa23313.png)
[Online deadlock analysis] by index_ Deadlock event caused by merge

Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken

matlab simulink实现模糊pid对中央空调时延温度控制系统控制

Great reward for interview questions

After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"

【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛

QT handy notes (III) use qtcharts to draw a line chart in VS

Due to fierce competition in the new market, China Mobile was forced to launch a restrictive ultra-low price 5g package

阿里云技术专家郝晨栋:云上可观测能力——问题的发现与定位实践

Logical architecture of MySQL
随机推荐
[MySQL] understand the important architecture of MySQL (I)
Redis sentinel mode setup under Windows
Qt随手笔记(二)Edit控件及float,QString转化、
E. Two Small Strings
The diagram of user login verification process is well written!
uni-app学习总结
R language ggplot2 visualization: align the legend title to the middle of the legend box in ggplot2 (default left alignment, align legend title to middle of legend)
Drawing shadow error diagram with MATLAB
服务器环境配置全过程
matlab simulink实现模糊pid对中央空调时延温度控制系统控制
Table extraction for opencv table recognition (2)
高斯消元
matlab中的AR模型短时预测交通流
Smart gourmet C language
Server and client dual authentication (2)
Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
[Online deadlock analysis] by index_ Deadlock event caused by merge
Interpretation of the standard of software programming level examination for teenagers_ second level
2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
POJ 1012 Joseph