search
HomeBackend DevelopmentPHP7A brief introduction to the underlying design of PHP7 01-PHP7 language execution principle

PHP is an interpreted language. Unlike compiled languages, the compilation result is the instruction of the current CPU system. PHP source code can only be directly executed by the zend virtual machine when it is compiled into opcode.

The following is a brief description of the PHP7 language execution principle:

1. The source code first uses the lexical analyzer implemented by Re2c for lexical analysis, and cuts the source code into multiple String unit, the divided string is called Token;

2. The syntax analyzer implemented based on Bison generates an abstract syntax tree from Token and code that conforms to BNF grammar rules;

3. Abstract syntax tree (AST) is compiled to generate opcode; process.

Not only that, unlike Java and other languages ​​that are resident in memory, the memory will be released immediately after the PHP code is executed, and basically all data will be destroyed at this time (only a very small amount of data will be cached). A brief introduction to the underlying design of PHP7 01-PHP7 language execution principle

The advantage of this execution mechanism is that it effectively avoids memory leaks and the memory recycling mechanism is simpler. The disadvantage is that each PHP request must repeat the request-translation-execution process.

Note: Memory Leak means that the dynamically allocated heap memory in the program is not released or cannot be released for some reason, causing a waste of system memory, causing the program to slow down or even crash the system. Wait for serious consequences.

In order to make up for the shortcoming of not being resident in memory, the opcode cache is introduced. The zend virtual machine caches the PHP code compilation result of the first execution into the memory or hard disk, and directly reads the cache when the next time this part of the code is executed. , which can improve PHP running speed to a certain extent.

Reference materials

1. Chen Lei, PHP7 underlying design and source code implementation

2. Lie Xusong, Chen Wen, PHP core technology and best practices

The above is the detailed content of A brief introduction to the underlying design of PHP7 01-PHP7 language execution principle. For more information, please follow other related articles on the PHP Chinese website!

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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools