A PHP instance, whether it is called from the init script or started from the command line, goes through the four processes of module INIT, request init, request shutdown, module shutdown, of course, This also executes the script's own logic, the two types of init and two shutdown each will execute how many times, the respective frequency of execution, depending on what PHP SAPI with the host communication, the most common four ways to start PHP are as follows:
1. Direct cli/cgi mode call
2. Multi-process Module
3. Multi-threaded module
4, embedded, in their own C program call Zend Engine
The SAPI (Server Abstraction Program Interface) provides an interface that allows PHP to interact with other applications, that is, PHP can interact with other programs such as Apache and this interface works
When you enter: Php-f test.php on the command line, the following procedure occurs
1, the registration of constants or class initialization work
2. Request the test.php file, when the request arrives, PHP initializes the underlying environment for executing the script, such as creating an execution environment, including a symbol table that holds the variable name and variable value contents of the PHP runtime, and a symbol table for all current functions and classes, and then PHP invokes the Rinit function for all modules, at this stage Individual modules can also perform a number of related operations.
3, the implementation of the test.php phase, the main is to edit the php file into opcodes, and then execute under the PHP virtual machine
4, the request after processing into the end stage, the general script execution to the end of the Exit function, and the beginning of the corresponding phase, the end stage is divided into two links, one at the end of the request, one at the end of the SAPI life cycle
From PHP core technologies and best practices
PHP life cycle