search
HomeBackend DevelopmentPHP Tutorial脚本语言是必然趋势,在开发成本面前,其他都是浮云。现在的问题是,把解释语言转成编译语言的转换器,如Java的JIT compiler,你认为最近Facebook开源的JIT PHP编译器及虚拟机,是否可以提供这种可能性?

回复内容:

HHVM是一个开源的PHP虚拟机,使用JIT的编译方式以及其他技术,让PHP代码的执行性能大幅提升。据传,可以将当前版本的原生PHP代码提升5-10倍的执行性能。

HHVM起源于Facebook公司,Facebook早起的很多代码是使用PHP来开发的,但是,随着业务的快速发展,PHP执 行效率成为越来越明显的问题。为了优化执行效率,Facebook在2008年就开始使用HipHop,这是一种PHP执行引擎,最初是为了将 Fackbook的大量PHP代码转成 C++,以提高性能和节约资源。使用HipHop的PHP代码在性能上有数倍的提升。后来,Facebook将HipHop平台开源,逐渐发展为现在的 HHVM。


HHVM提升PHP执行性能的方式

HHVM提升PHP性能的途径,采用的方式就是替代Zend引擎来生成和执行PHP的中间字节码(HHVM生成自己格式的中间字节 码),执行时通过JIT(Just In Time,即时编译是种软件优化技术,指在运行时才会去编译字节码为机器码)转为机器码执行。Zend引擎默认做法,是先编译为opcode,然后再逐条 执行,通常每条指令对应的是C语言级别的函数。如果我们产生大量重复的opcode(纯PHP写的代码和函数),对应的则是Zend多次逐条执行这些C代 码。而JIT所做的则是更进一步,将大量重复执行的字节码在运行的时候编译为机器码,达到提高执行效率的目的。通常,触发JIT的条件是代码或者函数被多 次重复调用。

脚本语言是必然趋势,在开发成本面前,其他都是浮云。现在的问题是,把解释语言转成编译语言的转换器,如Java的JIT compiler,你认为最近Facebook开源的JIT PHP编译器及虚拟机,是否可以提供这种可能性?

普通的PHP代码,因为无法固定变量的类型,需要额外添加判断类型的逻辑代码,这样PHP代码是不利于CPU执行和优化 的。因此,HHVM通常需要用到Hack写法(为了兼容某种特性而额外添加的技巧性质的代码)的PHP代码来“配合”,就是为了让变量类型固定,方便虚拟 机编译执行。PHP追求以一种形式来容纳一切类型,而Hack则可以将被容纳的一切标记上确定的类型。

PHP代码的Hack写法的例子:

脚本语言是必然趋势,在开发成本面前,其他都是浮云。现在的问题是,把解释语言转成编译语言的转换器,如Java的JIT compiler,你认为最近Facebook开源的JIT PHP编译器及虚拟机,是否可以提供这种可能性?

上面的例子中,PHP代码主要被添加上了变量类型。Hack写法的总体方向,就是将之前“动态”的写法变为“静态”的写法,来配合HHVM。

HHVM因为它的高性能而吸引了不少人的关注,一些一线互联网公司也开始跟进使用。从纯语言执行性能测试结果来看,HHVM领先了开发中的PHP7版本不少。

脚本语言是必然趋势,在开发成本面前,其他都是浮云。现在的问题是,把解释语言转成编译语言的转换器,如Java的JIT compiler,你认为最近Facebook开源的JIT PHP编译器及虚拟机,是否可以提供这种可能性?

不过,从具体业务场景来看,HHVM和PHP7的差距并没有那么大,以WordPress开源博客首页为测试场景的结果中,他们目前的差距并不明显。

脚本语言是必然趋势,在开发成本面前,其他都是浮云。现在的问题是,把解释语言转成编译语言的转换器,如Java的JIT compiler,你认为最近Facebook开源的JIT PHP编译器及虚拟机,是否可以提供这种可能性?

但是,PHP7目前还在开发中,就已经可用的技术方案来看,目前的HHVM略胜一筹。不过,HHVM的部署和应用都存在一些的问题:

  1. 服务部署比较复杂,有一定维护成本。
  2. 对PHP原生代码并非完整支持,PHP拓展也需要做适当的兼容。
  3. HHVM是个新虚拟机,长时间运行有内存泄露。(据说,一线互联网公司在应用这个技术时,是通过自己打Patch的方式解决内存泄露)
PS:PHP7是PHP官方社区的下一个大版本,旨在提升PHP代码的执行性能。

我之前整理的两个社区的科普文:
PHP7和HHVM的性能之争介绍 干。人家都把代码开源了你说有没有提供这种可能性? 不存在什么解释语言或者编译语言。
解释或者编译都是实现一个语言的方式。 JS和PHP的开发成本低,只能用呵呵来形容,,,,

要降低开发成本,语言只是其中一个因素,而且在JS和PHP实践中,这还是最不重要的一个因素。


静态类型语言不适合快速部署其实只是一种刻板印象而已,原因只是因为他们缺少行之有效的快速部署实践模式,尤其是WebForm的模式破产后。

如果配合轻量灵活的开发模式和框架,JS和PHP没有什么明显的优势可言。 脚本语言是个什么鬼啊!问题说了那么长一串可是概念的定义都混乱了啊。 JIT一般是VM的一部分,作为优化的其中一种手段,把“部分”字节码转换成机器码缓存,跟传统的缓存字节码(如Zend的一些缓存扩展)相比确实能大幅度提升速度,但是对于某些语句而言,JIT反而会降低性能,所以如果只从这个角度来讲,有些语句还是得直接经过interpreter或者VM的执行引擎,如果写高性能server,我肯定还是选c/c++,因为压榨单台机器的性能是非常让人兴奋的~而且通常的脚本语言涉及性能时通常也是配合c/c++写扩展~
so,没什么趋势不趋势的,适合才是王道。 hack语言。你值得拥有 你胡说!!渣华人到处都是,而且给少少钱就可以请来一堆,成本低低的…(逃
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 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.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

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.

See all articles

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

SecLists

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.

DVWA

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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.