PHP kernel exploration-interpreter execution process ,. The execution process of the interpreter for PHP kernel exploration. cli (CommandLineInterface) is the PHP command line mode. now this SAPI is installed by default. after installing PHP on the server, a php kernel exploration interpreter execution process,
Cli (Command Line Interface) is the PHP Command Line mode. now this SAPI is installed by default. after installing PHP on the server, an executable file is usually generated, suppose the file is/usr/local/bin/php, then we can run a PHP script using the following command in SHELL:
The code is as follows:
/Usr/local/bin/php-f test. php
Take cli sapi as an example to parse the core part of php execution. CLI is the php command line mode. this SAPI is installed by default. after PHP is installed on the server side, an executable file is generated. you can call the PHP command in shell to execute it.
The code is as follows:
PHP-f XX. php
Execution process:
Parse command line parameters;
Initialize the environment;
Compile and execute PHP code;
Clean up the environment and exit;
How to execute the PHP script in the 3rd phase:
Call php_execute_script (handle_file) to complete the third stage. This function will eventually call zend_execute_scipts (... ), This function is a variable parameter function that can execute multiple PHP scripts at a time.
In zend_execut_scripts (.....) The core function calls the (zend_compile_file) (compile_file) and (* zend_execute) (zend_op_array) functions;
Call zend_compile_file to compile the php script file specified by the parameter. This function returns a structure pointer of zend_op_array;
The input parameter zend_execute is the return value of zend_compile_file, and opcode is executed.
These two functions are Zend APIs and are a function pointer. the specific method for assigning values when the engine is initialized is called.
Ps: Why are these two Zend APIs function pointers?
During engine initialization, zend_execute and zend_compile_file point to the default method during engine initialization. We can compile and execute the rewrite function, which leaves a hook for our extension engine. For example, vld points zend_execute and zend_compile_file to the function encapsulated by the original function and adds the opcode output.
Articles you may be interested in:
- Php design mode Interpreter (Interpreter mode)
- In-depth analysis of the interpreter mode in PHP design mode
- PHP kernel exploration: usage instructions on variable storage and types
- PHP kernel exploration: variable overview
- PHP kernel exploration: hash table collision attack principle
- PHP kernel exploration variables
Cli (Command Line Interface) is the PHP Command Line mode. now this SAPI is installed by default. after installing PHP on the server, I...