search
HomeBackend DevelopmentPHP7An in-depth analysis of the underlying running process of PHP

This article will give you an in-depth analysis of the PHP Running process. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

An in-depth analysis of the underlying running process of PHP

#The underlying language of PHP is C language. C language is a compiled language.

Compiled language: The program requires a special compilation process before execution. The program is compiled into a machine language file. There is no need to re-translate when running. Just use the compiled results directly. . The program execution efficiency is high, it depends on the compiler, and its cross-platform performance is poor. How did it become an interpreted language?

I used processon to make a picture, and then I will continue to fill in the holes slowly

If the picture is not clear, you can see the original picture

An in-depth analysis of the underlying running process of PHPAddress: http://assets.processon.com/chart_image/603b293b1e08530bb1adcb1c.png

Briefly explain the process of the picture

First, do not consider the CLI and FPM processes C The language is parsed to the file with php suffix through the open_file_sanning function

2 Call the compilation function zend_compile_file() to compile. The specific implementation of this function actually includes two main processes: lexical analysis (Lex implementation) and syntax analysis (Yacc implementation). After executing this function: the compilation of the php script is complete. The input of this function is: php script file, and the output is op_array. To put it simply: the compilation process is to parse the script into instructions that the php virtual machine can process, and op_array is just an array made of these instructions ( This is very similar to the assembly code generated by compilation of some compiled languages. It is also a series of commands.

3 The VM virtual machine calls the zend_execute() function to execute. The input of this function is the op_array generated in the compilation stage above. Here he will parse each command and process it. There are nearly 200 op commands in PHP7.4.5, so it needs to process these commands. Each command has a corresponding processor for processing. The zend virtual virtual machine will be based on The type of each command in op_array is distributed to the corresponding processor for processing.

The processor here is the processor of the zend virtual machine. It is not the CPU

Zend virtual machine processor actually It is the logic for processing the op command. It can exist in the form of a function or a logical segment, depending on the command distribution method

Zend There are three mechanisms for distributing commands in the virtual machine: CALL , SWITCH, and GOTO are three types. Both switch and goto have corresponding logic segments in the zend_execute() function, which can be executed directly. And call executes function calls in the zend_execute() function.

You can find that the PHP code actually runs in the zend vm virtual machine and does not directly run in the CPU

The emergence of JIT in PHP8 can allow part of the code to be compiled into machine code Running in the CPU For this part, you can refer to the analysis done by @rhett's article "PHP JIT Technology Detailed Explanation". Article address: https://zhuanlan.zhihu.com/p/331777202

Thanks to senior Chen Lei for his "PHP7 Source code underlying design and implementation》

This article has been approved by the original author PHP Cui Xuefeng and published on the PHP Chinese website. The original address is: https://zhuanlan.zhihu.com/p/353501903


Recommended learning: "
PHP Video Tutorial

"

The above is the detailed content of An in-depth analysis of the underlying running process of PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:知乎. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor