Home Backend Development PHP Tutorial 最新版本PHP 7 vs HHVM 多角度比较_PHP

最新版本PHP 7 vs HHVM 多角度比较_PHP

May 28, 2016 am 11:48 AM

PHP 是最流行的用于 web 开发的脚本语言之一。PHP 的最新版本,PHP 7 在性能上做了很大的优化。不过,PHP 还有一个竞争对手 HHVM (HipHop Virtual Machine) — 一个运行 PHP 代码的虚拟工具。二者直接的比较正在升温,那么让我们来看一下他们直接的性能对比吧。

什么是 HHVM?

在2008年,Facebook 启动了一项工作,计划开发一个工具 将 PHP 脚本转换成 C++,这样就可以被编译后在 web 服务器上运行。目的是节省服务器资源,这是一个很重要的目标,因为 Facebook 的用户量正在快速增长。从这个意义上讲,这个项目是成功的,因为它可以让服务器处理之前五到六倍的请求量。

时间回到2010年,Facebook 的服务器需求已经增加了很多,是时候考虑用新的创新来提升更大的效率。基于这个需求,Facebook 开发了 HHVM。
HHVM 使用了 Just-In-Time (JIT) 编译方式将 PHP 代码转换成某种字节码。接下来把字节码再转换成机器码并进行优化,让它尽可能快的运行。

什么是PHP 7?

PHP 7 是 PHP 社区对 HHVM 的回应。PHP 7 发布的预览版本号称比之前的 PHP 5 的性能要提升100%。

你可能会问 PHP 的版本直接从 PHP5 跳到了 PHP7,答案是这样的:PHP6 的开发开始于2005年,但是它的进展过于缓慢又出现了很多的问题,这样 PHP6 在它还没有发布正式版本之前就有了不好的名声。所以PHP社区决定给这个语言的新版本直接命名为 PHP7。

真正的问题不是 PHP5 和 PHP7 之间的比较,因为已经很明显了 PHP7 提供了更快速的运行速度。但是我们想比较的是 PHP7 和 HHVM。很多专家已经分别使用了这两个方法来处理PHP代码,并且揭示了一些有趣的结论。

比较 PHP7 和 HHVM 的异同:

在回答哪个更好之前,让我们先来看一下他们之间的关键不同点和相似之处。

代码解析:

PHP7 和 HHVM 之间的基本不同之处在于他们解析 PHP 代码的方式。PHP7 使用标准的 PHP 解析器,它是一个可以给所有人使用的免费软件,可以在服务器上直接解析和运行。它生成 HTML 代码,然后发送给客户端,客户端显示出用户期望的内容。

相比之下,HHVM 首先把 PHP 代码转化为 HipHop 字节代码,这个代码再被翻译成机器码然后执行。在这个过程中 HHVM 会对代码进行优化,优化一些影响执行效率的 PHP 代码,目标是提高运行速度。

编写代码:

PHP 解析器和 HHVM 都可以接收 PHP 代码然后运行。这样写代码的过程是完全一样的。但是如果你想使用 HHVM,你需要在你的服务器上安装 HHVM 然后以命令行的方式通过 HHVM 命令来调用。

性能测试:

HHVM 比之前的 PHP 版本能提供更快速的性能。但是最近的性能测试认为至少在某些情况下 PHP7 是比 HHVM 稍微快些。让我们来看一下由 Kinsta 来做的性能测试结果:

WordPress:运行在WordPress4.1.1的 PHP7 每秒钟比 PHP5.6 能执行超过两倍的请求,但是没有 HHVM3.6.1 提供的多,在测试中 HHVM 每秒钟执行624个请求而 PHP7 只执行604个。

Drupal:PHP7 可以给 Drupal 用户提供比 HHVM 更加明显的优势。PHP7 在 Drupal8 上的处理响应效率比 HHVM 高出超过37个百分点。

那些公司使用 HHVM?

除了开发出 HHVM 的 FaceBook 公司外,还有很多其他公司也采用了这个方案,在服务器上用 HHVM 运行 PHP 应用,包括 Wikimedia 和电子商务网站 Etsy。

Wikimedia:Wikimedia 拥有大量的教育内容,包括著名的在线百科全书维基百科。维基百科每 个月吸引着近五亿的互联网用户,为了满足这样高级的需求,需要优化服务器的性能,和 PHP相比 HHVM 有一个显著的优点,它可以同时加载多个 SPU 核心, 而 PHP 是单线程语言,不能被并行化。维基百科部署了 HHVM 后,CPU 的负载从50%降到了10%,用户提交编辑时的平均响应时间减少到原来的一半,页面的平均加载时间从原来的1.3秒降到了0.9秒。

Etsy: 拥有五千四百万用户的 Tesy 同样迫切需要提高服务器性能,Etsy 的工程师对比了HHVM 和 PHP5.4 的性能,发现 HHVM 每秒可以处理280个服务器请求,而对于 PHP5.4,如果每秒的请求数超过了190次,服务器的响应时间就会急剧增加。

PHP 7 和 HHVM的前景如何?

由于 PHP 7 的稳定版本将在2015年11月发布,因此目前还没有公司使用这个新的语言,由于 PHP 7 的 beta 版在基准测试中表现出色,未来能够吸引更多公司使用 PHP 7。

PHP 的前途一片光明,那么 HHVM呢?它可能会继续活得很好。很多公司已经在网站中使用了 HHVM提高性能,在 PHP 和 HHVM 之间迁移不是一蹴而就的。Etsy 花了至少6个月的时间。由于 PHP7 和HHVM 相比性能提升不大,那些公司不太可能急于切换到PHP。

Facebook 仍然会继续开发 HHVM。它最近宣布支持苹果的操作系统,使在苹果开发环境下工作的开发者可以使用这个技术。HHVM 的开发者相信在很多情况下 HHVM 比 PHP7 更快,包括 WorldPress。

为什么 HHVM 和 PHP 7 对于网店老板存在竞争关系?

作为一个网店老板,你需要根据你的网店所在的平台决定是否使用 PHP7 或 HHVM。如果你的网站是用 WorldPress 创建的,那么你可以看看最新版本的 HHVM 和 PHP 7 的基准测试结果,从测试结果可以发现两者在性能上的差异,然后你就可以选择解决方案,最大限度地减小页面加载时间,服务器响应时间和 CPU 使用率。

选择 HHVM 的原因

HHVM 使用动态翻译技术,在大多数情况下(包括WordPress)可以提供更高的性能。

HHVM 在处理大量请求时,可以保证每个请求只使用少量的内存。

HHVM 开发者正在稳步增加这个引擎所能运行的 PHP 代码的数量,它已经可以运行最新版本的 WorldPress,以及其他常见的 PHP 框架和应用。

HHVM 是开源的,尽管 HHVM 是 Facebook 开发的,但它是开源的,意味着任何人都可以使用和修改它的源码。

选择 PHP 7 的理由

PHP 7 在某些情况下比 HHVM 更快,包括运行 Drupal 8。

使用 PHP 7 不需要安装设置 HHVM。

尽管很多 PHP 4 的功能在新版本中不再支持,但用 PHP 5 写的代码在转换到 PHP 7 后将会如预期一样工作。

PHP 7 由 PHP 社区开发,这是一群开发稳定可靠 PHP 版本久负盛名的人。

HHVM vs. PHP 7: 作出你的选择

不要犹豫太久,Kinsta 建议那些在线的网站尽量在 PHP 7 与 HHVM 之间作出选择,早点开始实施解决方案,让你的网站性能得到优化。一个低效的网站也会让你的声誉受损,那将很难挽回。

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

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

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: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

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 in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

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.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

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 vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

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 and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

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.

See all articles