Home > Backend Development > PHP Tutorial > The latest brief analysis of PHP features, kernel and architecture in 2022

The latest brief analysis of PHP features, kernel and architecture in 2022

藏色散人
Release: 2023-04-11 07:24:02
forward
3047 people have browsed it

Features of PHP8?

1. JIT just-in-time compiler. On the basis of opcache optimization, jit optimizes again combined with runtime information to directly generate machine code. JIT is not a replacement for opcache optimization, but an enhancement.

2. Match expression, used for value conversion and assignment of variables.

3. Union type.

Supports declaration and acceptance of multiple different types. It is a collection of two or more types.

4. static return type. Support for static return types in PHP 8 will be more efficient.

5. Weak mapping WeakMap. Allows keys in arrays to be placed into objects.

6. Class changes, use

  • 1. Variable parameter inheritance (tasteless), allowed

  • 2. Late static binding (LSB) (useful), useful for framework-level encapsulation and some factory design patterns.

  • 3. Now you can use the following method to get the class name of the object

  • 4. Now, new and instanceof can be used with any expression , use new(expression)(... $args) and $obj instanceof(expression).

  • 5. Writing is now allowed.

  • 6. Add Stringable interface (general function, used in view template encapsulation).

  • 7. Trait can now define abstract private methods.

New features of PHP7? (Difference from PHP5)

1. Scalar type declaration and return value type declaration.

2. null coalescing operator (??)

3. Namespace reference use enhancement: classes, functions and constants imported from the same namespace can now be imported at once through a single use statement

4. Anonymous class: now supports instantiating an anonymous class through new class

5. The performance is 2 times higher than that of php5.

6. Support 64-bit.

Why is the performance of php7 improved compared to php5?

1. The variable storage bytes are reduced. Reduce memory usage, improve variable operation speed

2, and improve array structure. Array elements and hash mapping tables are allocated in the same memory, which reduces memory usage, improves CPU cache hit rate

3, and improves the function calling mechanism. By optimizing the parameter transfer process, some instructions are reduced and execution efficiency is improved.

PHP7 execution process?

The latest brief analysis of PHP features, kernel and architecture in 2022

Lexical analysis, cutting the source code into multiple string units (Token)

The syntax analyzer converts Token into AST abstract grammar Tree

The abstract syntax tree is converted into opcodes (opcode instruction set)

Virtual machine interprets and executes opcodes (opcode is a set of instruction identifiers, corresponding to the handler processing function)

In web mode, PHP life cycle?

SAPI runs PHP through the following stages:

1. Module initialization stage (module init):

This stage mainly carries out the initialization operations of the PHP framework and zend engine. . This stage is generally executed once when SAPI starts. For FPM, it is executed when the fpm master starts. PHP loads the code of each extension and calls its module initialization routine (MINIT) to apply for some variables required by the module, allocate memory, etc.

2. Request initialization phase (request init):

When a page request occurs, it is a stage that will be experienced before the request is processed. For fpm, it is a stage after the worker process accepts a request and reads and parses the request data. During this stage, the SAPI layer hands over control to the PHP layer, and PHP initializes the environment variables required to execute the script for this request.

3. PHP script execution stage:

The process of PHP code parsing and execution. The Zend engine takes over control, compiles the PHP script code into opcodes and executes it sequentially

4. Request shutdown:

After the request is processed, it enters the shutdown phase, PHP The cleanup process will be started. At this stage, the output content will be flushed, the http response content will be sent, etc., and then it will call the RSHUTDOWN method of each module in sequence. RSHUTDOWN is used to clear the symbol table generated when the program is running, that is, to call the unset function on each variable.

5. Module shutdown:

This stage is executed when SAPI is closed, corresponding to the module initialization stage. This stage mainly cleans resources and closes each PHP module. At the same time, the module shutdown hook function of each extension will be called back. This happens after all requests have been completed, such as shutting down fpm. (This is for SAPI such as CGI and CLI. There is no "next request", so the SAPI starts to close immediately.)

What is the php7 architecture?

The latest brief analysis of PHP features, kernel and architecture in 2022

Zend engine: Zend engine provides basic services for PHP, including lexical analysis and syntax analysis, AST abstract syntax tree compilation opcodes execution, PHP variable design, and memory Management, process management.

PHP layer: Binds the SAPI layer and handles communication with it. It also provides a consistent control layer for the detection of safe_mode and open_basedir, and integrates user spaces such as fopen(), fread() and fwrite() functions associated with file and network I/O.

SAPI: Including cli fpm, etc., which abstracts the external interfaces. As long as the SAPI protocol is followed, a server can be implemented.

Expansion: zend engine provides core capabilities and interface specifications. On this basis, you can develop and expand

php data implementation?

The underlying implementation of PHP data is a hash table (also called hashTable)

What is PHP’s garbage collection mechanism?

PHP can automatically manage memory and clear unnecessary objects.

PHP uses the reference counting GC mechanism.

Each object contains a reference counter refcount. Each reference is connected to the object and the counter is incremented by 1. When reference leaves the living space or is set to NULL, the counter is decremented by 1. When an object's reference counter reaches zero, PHP knows that you no longer need to use the object and releases the memory space it occupies.

#What is the architecture model of PHP-FPM? How have you optimized it?

It is an architectural pattern of master and worker. Work handles requests, and master manages and recycles child processes.

For optimization, the configuration of the number of processes has been changed.

Briefly describe: Due to the static mode configured before, the default number of processes was 200. Later, there was a certain concurrency, so I should change it to the "third" configuration mode and configure the specified number of processes. , there is a minimum value and a maximum value (the maximum value is actually forgotten here, I just think there must be no limit, after all, hardware resources are the ceiling), and then dynamically increase the number of processes based on the actual number of requests.                                                                                                                                                                                                

The above is the detailed content of The latest brief analysis of PHP features, kernel and architecture in 2022. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template