


脚本语言是必然趋势,在开发成本面前,其他都是浮云。现在的问题是,把解释语言转成编译语言的转换器,如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的条件是代码或者函数被多 次重复调用。

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

上面的例子中,PHP代码主要被添加上了变量类型。Hack写法的总体方向,就是将之前“动态”的写法变为“静态”的写法,来配合HHVM。
HHVM因为它的高性能而吸引了不少人的关注,一些一线互联网公司也开始跟进使用。从纯语言执行性能测试结果来看,HHVM领先了开发中的PHP7版本不少。

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

但是,PHP7目前还在开发中,就已经可用的技术方案来看,目前的HHVM略胜一筹。不过,HHVM的部署和应用都存在一些的问题:
- 服务部署比较复杂,有一定维护成本。
- 对PHP原生代码并非完整支持,PHP拓展也需要做适当的兼容。
- HHVM是个新虚拟机,长时间运行有内存泄露。(据说,一线互联网公司在应用这个技术时,是通过自己打Patch的方式解决内存泄露)
我之前整理的两个社区的科普文:
PHP7和HHVM的性能之争介绍 干。人家都把代码开源了你说有没有提供这种可能性? 不存在什么解释语言或者编译语言。
解释或者编译都是实现一个语言的方式。 JS和PHP的开发成本低,只能用呵呵来形容,,,,
要降低开发成本,语言只是其中一个因素,而且在JS和PHP实践中,这还是最不重要的一个因素。
静态类型语言不适合快速部署其实只是一种刻板印象而已,原因只是因为他们缺少行之有效的快速部署实践模式,尤其是WebForm的模式破产后。
如果配合轻量灵活的开发模式和框架,JS和PHP没有什么明显的优势可言。 脚本语言是个什么鬼啊!问题说了那么长一串可是概念的定义都混乱了啊。 JIT一般是VM的一部分,作为优化的其中一种手段,把“部分”字节码转换成机器码缓存,跟传统的缓存字节码(如Zend的一些缓存扩展)相比确实能大幅度提升速度,但是对于某些语句而言,JIT反而会降低性能,所以如果只从这个角度来讲,有些语句还是得直接经过interpreter或者VM的执行引擎,如果写高性能server,我肯定还是选c/c++,因为压榨单台机器的性能是非常让人兴奋的~而且通常的脚本语言涉及性能时通常也是配合c/c++写扩展~
so,没什么趋势不趋势的,适合才是王道。 hack语言。你值得拥有 你胡说!!渣华人到处都是,而且给少少钱就可以请来一堆,成本低低的…(逃

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





Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
