Home > Backend Development > PHP Tutorial > PHP kernel exploration of the execution process of the interpreter

PHP kernel exploration of the execution process of the interpreter

WBOY
Release: 2016-07-29 09:09:36
Original
1110 people have browsed it

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:

Copy the code The code is as follows:


/usr/local/bin/php -f test.php

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.

Copy the code The code is as follows:


PHP -f XX.php

Execution process:

Parse the command line parameters;

Initialize the environment;

Compile and execute the PHP code;

Clean up 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), which will eventually call zend_execute_scipts(…), this function is A variable parameter function that can execute multiple PHP scripts at once.

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

By calling zend_compile_file to compile the php script file specified by the parameter, this function will Returns a zend_op_array structure pointer; the parameter passed in to

zend_execute is the return value of zend_compile_file, and 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.

The above introduces the execution process of the interpreter for PHP kernel exploration, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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