CLI (command line Interface) that is PHP, this SAPI is installed by default, after we install PHP on the server, we usually generate an executable file, assuming this file is/usr/local/bin/php, Then we can execute a PHP script with the following command under the shell:
Copy the Code code as follows:
/usr/local/bin/php-f test.php
Take the 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 the server side installed PHP, generated as an executable file, you can invoke PHP command in the shell to execute.
Copy the Code code as follows:
Php-f xx.php
Execution process:
Parse command line arguments;
Initializing the environment;
Compile and execute PHP code;
Clean up the environment and exit;
In the 3rd phase, how to execute a PHP script:
by calling Php_execute_script (Handle_file) to complete the third phase, the function will eventually call Zend_execute_scipts (...), which is a variable parameter function that can execute multiple PHP scripts at once.
In the Zend_execut_scripts (...) The functions in the core call the (Zend_compile_file) (Compile_file), (*zend_execute) (Zend_op_array) these two functions;
By invoking the PHP script file specified by the zend_compile_file compilation parameter, the function returns a zend_op_array structure pointer;
Zend_execute the passed-in parameter is the return value of zend_compile_file, the opcode is executed.
These two functions are the Zend API, which is a function pointer that is assigned a specific method when the engine is initialized.
PS.: So why are these two Zend APIs a function pointer?
At the time of engine initialization, Zend_execute and Zend_compile_file will point to the default method when the engine is initialized. We can compile and execute the point of the rewrite function, which leaves a hook for us to extend the engine. For example: VLD points Zend_execute and zend_compile_file to their own functions encapsulated in the original function, adding the output of the opcode information.
The above describes the PHP kernel to explore the implementation of the interpreter, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.