


The latest brief analysis of PHP features, kernel and architecture in 2022
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?
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?
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!

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

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

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 is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
