Detailed explanation of the execution of PHP kernel interpreter

*文
Release: 2023-03-19 10:04:01
Original
1850 people have browsed it

This article mainly introduces relevant information on the execution process of the interpreter for PHP kernel exploration. Friends in need can refer to it. I hope to be helpful.

cli (Command Line Interface) is the command line mode of PHP. Now this SAPI is installed by default. After we install PHP on the server, an executable file will generally be generated. Assume that this file is /usr /local/bin/php, then we can use the following command to execute a PHP script under SHELL:

/usr/local/bin/php -f test.php
Copy after login

Take CLI SAPI as an example to analyze 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, which can be executed by calling the PHP command in the shell.

PHP -f XX.php
Copy after login

Execution process:

Parse command line parameters;

Initialize the environment;

Compile and execute PHP code;

Clean the environment and exit;

In the third stage, how to execute the PHP script:

Complete the third stage by calling php_execute_script(handle_file). This function will eventually call zend_execute_scipts(...). This function is a variable parameter function that can execute multiple PHP scripts at one time.

In the zend_execut_scripts(…..) function, the core calls the two functions (zend_compile_file)(compile_file) and (*zend_execute)(zend_op_array);

Compile by calling zend_compile_file For the php script file specified by the parameter, this function will return a zend_op_array structure pointer;

The parameter passed in to zend_execute is the return value of zend_compile_file, and the opcode begins to be executed.

These two functions are Zend API, which is a function pointer that returns specific methods when the engine is initialized.

ps.: So why are these two Zend APIs function pointers?

When the engine is initialized, zend_execute and zend_compile_file will point to the default method when the engine is initialized. We can override function pointers during compilation and execution, leaving hooks for us to extend the engine. For example: vld points zend_execute and zend_compile_file to its own function that encapsulates the original function, and adds the output of opcode information.

Related recommendations:

Detailed explanation of the memo pattern of PHP design patterns

Detailed explanation of how PHP implements commission calculation through recursion

Detailed explanation of how PHP implements consistent hashing algorithm

The above is the detailed content of Detailed explanation of the execution of PHP kernel interpreter. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template