Home Backend Development PHP7 An in-depth analysis of the underlying running process of PHP

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

Jun 10, 2021 pm 02:39 PM
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 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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles