PHP infrastructure

1. sapi: PHP is a script parser that provides script parsing and execution. It inputs ordinary scripts, and then the parser parses and executes them according to predefined grammar rules. We can apply this parser in different environments, such as command line and web environment. For this reason, PHP provides a sapi layer to adapt to different application environments. Sapi can be recognized as the host environment of PHP, and aspi is also the entire PHP environment. The outermost part of the frame. It is mainly responsible for the initialization of the PHP framework. Two sapis that are often used are cli and fpm.

2. zendVM: The core implementation of the PHP language, it is mainly composed of two parts: the compiler and the executor. The compiler is responsible for interpreting the PHP code into instructions recognized by the executor, and the executor is responsible for executing the instructions interpreted by the compiler

3, extension; extension is a set of methods provided by the PHP kernel to expand PHP functions.

 

The entire life cycle of PHP is divided into the following phases:

1. Module initialization stage (activate sapi, start PHP output, initialize garbage collector, and zend engine)

2. Request initialization phase

3. Execute the script stage (compiling and executing PHP code, this is the most important function of the zend engine. In the compilation stage, the PHP script will go through the conversion process from PHP source code to abstract syntax tree and then to opline instructions. The final generated opline instruction is Execution code recognized by the zend engine)

4. Request close phase

5. Module closing stage.

According to the implementation of different sapi, there will be some differences in the execution of each stage. For example, in command line mode, each time a script is executed, it will go through these stages completely, while in fastcgi mode, a module initialization is performed at startup, and then Each request only tries its best to request initialization, script execution, and request shutdown stages, and goes through the module shutdown stage when sapi is closed.

 

Life cycle: main()->module initialization phase (php_module_startup())->request initialization phase (php_request_startup())-script execution phase (php_execute_script())-request shutdown phase (php_request_shutdown)-module shutdown phase (php_module_shutdown)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324384505&siteId=291194637