An 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.
#The underlying language of PHP is C language. C language is a compiled language.
If the picture is not clear, you can see the original pictureCompiled 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
Address: http://assets.processon.com/chart_image/603b293b1e08530bb1adcb1c.png
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.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
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 methodZend 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/331777202Thanks 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/353501903PHP 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
