


This article mainly introduces relevant information to help you understand the key to doubling the performance of PHP7. Friends in need can refer to it. I hope to be helpful.
PHP 7 is the first major revision in ten years. The biggest feature is a major breakthrough in performance. It can be twice as fast as the previous version of PHP 5. Rasmus Lerdorf, the father of PHP, said that it is even faster than HHVM virtualization. The performance of PHP programs under the computer is faster.
HHVM is a PHP optimization mechanism customized by Facebook for the characteristics of its own website, and may not be applicable to any website. But Rasmus Lerdorf said that one of the goals of the new version is to enable any website developer, even when using the development framework Drupal and the open source e-commerce system Opencart, to have the same performance as using HHVM technology. On the eve of the release of the new version, he also took the opportunity to come to Taiwan to attend the PHPConf Taiwan annual conference to share the key to the performance breakthrough of PHP 7.
It is not easy for a mature language that has gone through many revisions and countless optimizations in the past 20 years to have a breakthrough that doubles its performance. Rasmus Lerdorf admits that it is not as easy to find as most new projects. There is room for improvement. The new version of PHP does not achieve such results by modifying some programs. On the contrary, after a lot of detailed optimization and performance accumulation, PHP 7 has an execution performance that is not inferior to HHVM.
Rasmus Lerdorf and the PHP core contribution team have spent a lot of effort to reduce the number of memory bits moved when the program is running, thereby speeding up execution performance. For example, the data structure zval for storing variables in PHP is reduced from 24 bits to 16 bits, and Hashtable is reduced from 72 bits to 56 bits. The functions in PHP are reviewed to consider whether there is any room for improvement in performance.
In addition to reducing memory usage, Rasmus Lerdorf also examined the operating principle of the CPU's Cache line to understand how the program code interacts with the CPU, how the compiler compiles the program code under the new CPU architecture, and other details to ensure The program code of PHP 7 conforms to the architecture of modern CPUs. Although the optimization of each project contributes less than 0.5% to performance, because there are many optimization projects, or a certain improved function is repeatedly called by the application, the overall effect of the correction can make such a big progress.
Inspired by HHVM, we decided to build PHP with both performance and functionality
In order to optimize PHP operation, Facebook created the virtual machine HHVM with JIT compilation. Although HHVM has fast execution performance, its design optimized for specific purposes can only satisfy a small number of developers. On the contrary, in addition to improving the performance of PHP, Rasmus Lerdorf also wants to meet the needs of high-end users and amateur users at the same time, making PHP 7 a programming language with both performance and general functions.
However, it is not difficult to develop a programming language that meets the needs of a small number of people in the market. However, the PHP project aims at many targets and must meet the needs of amateur users and professional developers at the same time. It is difficult to develop everything because There will always be some groups whose needs cannot be met. "It's like spraying a large area with a water pipe. Everyone's clothes will be a little wet, but no one's clothes will be completely soaked." Rasmus Lerdorf said.
The computing performance of PHP without the use of external frameworks is very good. However, due to the influence of external frameworks, the performance of PHP, which could originally process thousands of web page requests in a few seconds, has dropped significantly and it can only process Dozens of requests. Rasmus Lerdorf said that before the emergence of HHVM, users were more concerned about whether PHP could reduce the difficulty of web development than the performance requirements of PHP, and these frameworks can make developers' work easier. However, after Facebook launched HHVM, it attracted many users who valued PHP performance, making Rasmus Lerdorf realize that many users have performance needs. He began to think about how to integrate HHVM's JIT architecture with PHP.
But Rasmus Lerdorf said that PHP and HHVM are quite different in architectural design. For example, HHVM's multi-threaded architecture is not very stable. In addition, the portability of HHVM is not good, and it is still a long way from being able to run on the Windows platform. PHP has many developers developing in the Windows environment, and HHVM cannot take care of those users.
Rasmus Lerdorf said that he could not give up the main architecture of PHP. Although they had considered integrating the two, HHVM had many limitations in its use. Although HHVM is a very good tool for Facebook and many developers, for PHP projects, the scope of use of HHVM is not broad enough and can only meet the needs of specific projects such as Facebook or Wikipedia.
For PHP, which is not a strongly typed language, it is even more difficult to import JIT
However, adding JIT compilation to PHP is very difficult. Rasmus Lerdorf said that JIT must learn to identify the operating patterns (Patterns) of the program, such as understanding which parts are important program codes, and predicting when the program will be called or which parts of the program will be called before the program is run.
Rasmus Lerdorf said that in many cars, JIT must be able to predict which part of the car will turn right, which part of the car will turn left, or which cars of certain colors will go straight. "And JIT must predict all of them." Correct, otherwise the performance will be greatly reduced. "However, if the prediction is correct, the program execution performance will be greatly improved.
It is not easy to add JIT to the compilation of general programming languages. Rasmus Lerdorf said that it is even more difficult to add JIT due to the dynamic nature of PHP. For example, he said that the developer declared the value of parameter $a to be 1, but it does not mean that the value of all $a in the program is 1, because the parameter value can be easily redefined in PHP. In C language, when the developer declares parameter a to be an integer, then a will always be an integer. If anywhere in the program declares that a is a type other than integer, even compilation will not be possible. And because C language is a strongly typed programming language, "JIT can predict that variable a is an integer, but in PHP, we don't have this luxury." He explained that HHVM's approach is that when JIT learns that a is an integer type After that, it is assumed that a is always an integer.
In order to use JIT compilation, HHVM has limited the development of PHP to some extent. Users of HHVM must clearly declare the nature of variables, but developers using PHP can first declare a category (Class) without nature, and then specify the variable attributes of the class. "Without any restrictions, adding JIT to PHP is what we have to do." He said that PHP must take into account developers of WordPress, Drupal and other frameworks, and cannot arbitrarily stop supporting these frameworks. Therefore, compared with HHVM, PHP has more restrictions on creating JIT.
However, "This does not mean that we cannot do JIT. In addition, we must also control the development direction of PHP." Rasmus Lerdorf said.
Currently, Dmitry Stogov, one of the core contributors to PHP, is developing a prototype JIT and using some experimental applications to test operation. Rasmus Lerdorf said that if this JIT is used to perform certain repetitive operations or loop programs, the performance of PHP 7 can be made 10 times faster.
However, he also admitted that when this experimental JIT was used in WordPress, it did not achieve any acceleration effect. "The JIT we want to create is not something learned in college textbooks, but something that can be learned in college textbooks." JIT working in the real world," he said. Because PHP has always held such ideals, trying to solve problems in people's lives and operating in real-world online environments, not just theories in textbooks.
Rasmus Lerdorf said that when PHP first came out, he spent at least 16 hours a day developing PHP. But now he has gradually reduced his investment in development and instead devoted his energy to publicity and speeches around the world. He jokingly said: "Instead of developing it myself, it is better to inspire people who are far smarter than me and willing to spend eighteen hours a day to write programs to develop PHP." He said that his ultimate goal is that there is not a single line in PHP written by him. Programming code, "Any growing project should not be led by one developer. Old program code should be replaced with new program code." And he believes that other developers should aim for this.
Related recommendations:
Detailed explanation of how PHP implements operable verification codes
Detailed explanation of how PHP implements file search
Detailed explanation of how PHP jumps to the corresponding web page according to the user language
The above is the detailed content of Detailed explanation of the key to doubling the performance of PHP7. For more information, please follow other related articles on the PHP Chinese website!

在php5中,我们可以使用fsockopen()函数来检测TCP端口。这个函数可以用来打开一个网络连接和进行一些网络通信。但是在php7中,fsockopen()函数可能会遇到一些问题,例如无法打开端口、无法连接到服务器等。为了解决这个问题,我们可以使用socket_create()函数和socket_connect()函数来检测TCP端口。

php7.0安装mongo扩展的方法:1、创建mongodb用户组和用户;2、下载mongodb源码包,并将源码包放到“/usr/local/src/”目录下;3、进入“src/”目录;4、解压源码包;5、创建mongodb文件目录;6、将文件复制到“mongodb/”目录;7、创建mongodb配置文件并修改配置即可。

解决 PHP 7.0 中插件未显示已安装问题的方法:检查插件配置并启用插件。重新启动 PHP 以应用配置更改。检查插件文件权限,确保其正确。安装丢失的依赖项,以确保插件正常运行。如果其他步骤均失败,则重建 PHP。其他可能原因包括插件版本不兼容、加载错误版本或 PHP 配置问题。

php7.0安装部署的方法:1、到PHP官网下载与本机系统对应的安装版本;2、将下载的zip文件解压到指定目录;3、打开命令行窗口,在“E:\php7”目录下运行“php -v”命令即可。

PHP8相较于PHP7在性能、新特性和语法改进、类型系统、错误处理和扩展等方面都有一些优势和改进。然而,选择使用哪个版本要根据具体的需求和项目情况来决定。详细介绍:1、性能提升,PHP8引入了Just-in-Time(JIT)编译器,可以提高代码的执行速度;2、新特性和语法改进,PHP8支持命名参数和可选参数的声明,使得函数调用更加灵活;引入了匿名类、属性的类型声明等等。

PHP服务器环境常见的解决方法包括:确保已安装正确的PHP版本和已复制相关文件到模块目录。临时或永久禁用SELinux。检查并配置PHP.ini,确保已添加必要的扩展和进行正确设置。启动或重启PHP-FPM服务。检查DNS设置是否存在解析问题。

本地环境:redhat6.7系统。nginx1.12.1,php7.1.0,代码使用yii2框架问题:本地的web站需要用到elasticsearch服务。当php使用本地服务器搭建的elasticsearch时,本地的负载都是正常。当我使用aws的elasticsearchservice服务时,本地服务器出现负载经常过高的情况。查看nginx和php日志,发现没有异常。系统的并发连接数也不高。这时候想到我们老大给我讲的一个strace诊断工具。调试过程:查找一个php的子进程idstrace-

如何在系统重启后自动设置unixsocket的权限每次系统重启后,我们都需要执行以下命令来修改unixsocket的权限:sudo...


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

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.