Home  >  Article  >  Backend Development  >  PHP kernel exploration of the execution process of the interpreter, _PHP tutorial

PHP kernel exploration of the execution process of the interpreter, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:36857browse

The execution process of the interpreter for PHP kernel exploration,

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

Copy 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 code 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;

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 one time.

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

By calling zend_compile_file to compile 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 starts 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 methods 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.

Articles you may be interested in:

  • php design pattern Interpreter (interpreter mode)
  • In-depth analysis of the interpreter mode of PHP design pattern
  • PHP kernel exploration: variable storage and type usage instructions
  • PHP kernel exploration: variable overview
  • PHP kernel exploration: hash table collision attack principle
  • PHP kernel exploration variables

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084570.htmlTechArticleThe execution process of the interpreter for PHP kernel exploration, 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,...
Statement:
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