热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

phphhvm_PHP与PHPNG对抗HHVM和Zephir

phphhvmThisarticlewassponsoredbyNewRelic.ThankyouforsupportingthesponsorswhomakeSitePointp

php hhvm

This article was sponsored by NewRelic. Thank you for supporting the sponsors who make SitePoint possible!

本文由NewRelic赞助。 感谢您支持使SitePoint成为可能的赞助商!

A previous version of this article incorrectly stated that PHPNG is JIT. This is not the case, and the necessary amendments have been made. See bottom of article for more info.

本文的先前版本错误地指出PHPNG是JIT。 事实并非如此,已经进行了必要的修改。 有关更多信息,请参见文章底部。



Chaos in the old world! First HipHop, years ago, and no one bats an eye. Then suddenly, HHVM happens, introduces Hack, and all hell breaks loose – Facebook made a new PHP and broke/fixed everything (depending on who you ask). Furthermore, Zephir spawns and threatens with C-level compilation of all your PHP code, with full support for current PHP extensions (while Zephir is not intended to replace C or PHP, it does let you write near-PHP code and compile it to C, which lets you easily rewrite all your PHP apps to a format that can be close-sourced and compiled for speed and security). It’s mushroom growth time for alternative PHP runtimes, and HippyVM appears as well.

旧世界的混乱! 多年前的《第一HipHop》,没有人引人注目。 然后突然出现了HHVM ,引入了Hack ,然后一切都变得一团糟– Facebook制作了新PHP并破坏/修复了所有内容(取决于您要求的人)。 此外, Zephir产生并威胁您所有PHP代码的C级编译,并全面支持当前PHP扩展(虽然Zephir并非旨在取代C或PHP,但它确实允许您编写近PHP代码并将其编译为C ,可让您轻松地将所有PHP应用程序重写为一种可以关闭源代码并进行编译以提高速度和安全性的格式。 对于替代PHP运行时,这是蘑菇式增长的时间,同时HippyVM也出现了。

Amid the sea of changes, another splash was heard: PHPNG.

在变化的海洋中,听到了另一个轰动: PHPNG 。

As introduced by Manuel Lemos, PHPNG is a new branch of PHP coming to a yet undetermined future version of PHP.

正如Manuel Lemos所介绍的那样 ,PHPNG是PHP的一个新分支,用于尚未确定PHP未来版本。

等一下 (Wait, what?)

This somewhat cheesily named (NG = new generation) and clumsily presented version of PHP is the core team’s attempt to optimize PHP drastically and allow JIT compilers in the future to push it even further. PHPNG is not a JIT, but an upgrade that allows the construction of a good JIT compiler later on. The PHPNG branch on its own does not include any JIT features.

这个有点俗气的名称(NG =新一代)和笨拙PHP版本,是核心团队试图彻底优化PHP并允许JIT编译器在将来进一步推广它的尝试。 PHPNG 不是 JIT,而是一种升级,它允许以后构造一个好的JIT编译器。 PHPNG分支本身不包含任何JIT功能 。

PHPNG was presented by Dmitry Stogov in an internals newsgroup thread. Dmitry is responsible for performance and optimization at Zend, and mostly deals with the Zend Engine. The NG upgrade focuses on rewriting core parts of the Zend Engine to enable better memory allocation on PHP’s data types.

PHPNG 由Dmitry Stogov在内部新闻组线程中提出。 Dmitry负责Zend的性能和优化,主要负责Zend Engine。 NG升级侧重于重写Zend Engine的核心部分,以实现对PHP数据类型更好的内存分配。

As quoted from Reddit:

从Reddit引用:

NG exists because the experiments conducted by Zend in introducing a JIT failed in the real world because of the way the engine is currently designed, mostly because we allocate everything all the time. The NG patch changes the norm, so that we no longer by default allocate zvals, this increases performance and allowed for much tidier API’s.

NG之所以存在是因为Zend引入JIT的实验在现实世界中由于引擎的当前设计方式而失败,主要是因为我们一直在分配所有东西。 NG修补程序更改了规范,因此我们默认不再分配zval,从而提高了性能并允许使用许多更整齐的API。

As with any “Make PHP better” attempt, this one has its pros and cons.

与任何“使PHP更好”的尝试一样,这也有其优点和缺点。

优点 (Pros)

速度! (Speed!)

Faster execution means faster resource allocation, means faster request processing, means bigger request throughput. Initial results are promising (1, 2).

更快的执行意味着更快的资源分配,意味着更快的请求处理,意味着更大的请求吞吐量。 初步结果是有希望的( 1 , 2 )。

The performance still needs to be benchmarked against other alternative solutions, but 10-30% is nothing to scoff at.

仍然需要将性能与其他替代解决方案进行基准测试,但是10%至30%的优势值得我们关注。

扩展! (Extensions!)

Since this upgrade is being done on the official Zend Engine, not an alternative runtime, it pretty much guarantees compatibility with current extensions. One of the biggest reasons for people hesitating about a transfer to HHVM is the unavailability of essential extensions they’re used to (Phalcon, in my case). Personally, a faster engine for PHP that supports Phalcon would make me care significantly less about the upgrades Hack offers today.

由于此升级是在官方的Zend Engine上完成的,而不是替代的运行时,因此几乎可以保证与当前扩展的兼容性。 人们对转移到HHVM犹豫不决的最大原因之一是无法使用他们惯用的基本扩展(在我的案例中为Phalcon)。 就个人而言,支持PhalconPHP更快的引擎将使我不必再在乎Hack提供的升级了。

So it guarantees extensions compatibility… wait. Does it? Uh oh.

因此,它保证了扩展兼容性...等等。 可以? 哦哦

缺点 (Cons)

扩展! (Extensions!)

Too good to be true.

难以置信。

Not all extensions are supported, some tests are failing, and we also have more ideas for additional improvement.

并非所有扩展都受支持,某些测试失败,并且我们还有更多改进的想法。

In all fairness, NG is young. Far younger than anything we’ve ever really dealt with in the PHP world, and far more of a serious update – so it goes without saying that some compatibility issues are guaranteed. But I agree with Manuel here when he says this might be the pain point for most shared hosting providers when the time to upgrade comes.

公平地说,NG很年轻。 比我们在PHP世界中真正处理过的任何事物都年轻得多,而且远远超过了任何严肃的更新–因此,不言而喻,可以保证某些兼容性问题。 但是我在这里同意Manuel的观点,当他说升级时机到来时,这可能是大多数共享主机提供商的痛苦点。

Even though I’m quite vocal against shared hosting providers, I fully understand the problem this might pose. We’ve had a similar mess when we tried to make providers “Go PHP5”, and quite recently once more when they needed talking into more up to date versions of PHP, so getting them to make a big shift that has the potential to introduce BC breaks will be a daunting task.

即使我反对共享托管服务提供商,我也完全理解这可能带来的问题。 当我们尝试使提供程序变成“ Go PHP5”时,我们也遇到了类似的麻烦。最近,当他们需要讨论更多最新版本PHP时,我们又遇到了类似的麻烦,因此使他们做出重大转变,有可能引入卑诗省休息将是一项艰巨的任务。

This fear of change will cement the use of old PHP versions, in turn breeding more horribly unqualified PHP developers working on outdated code, completely oblivious to best practices and vulnerabilities. In short, we’re due for a replay of history. This might sound doomsday-ish, as some have pointed out, but being deeply involved in all circles of PHP and exposed to the lowest quality ones on a daily basis through a full inbox, I see where we are now and where we’re going. All is not black, however – solutions such as Heroku and DigitalOcean will let people run the most up to date and custom versions of PHP possible for prices as low as (or lower) than that of shared hosting providers.

这种对变更的恐惧将巩固旧PHP版本的使用,进而滋生出处理过时代码的更可怕的不合格PHP开发人员,而这些开发人员完全不了解最佳实践和漏洞。 简而言之,我们应该重温历史。 正如某些人指出的那样,这听起来似乎是世界末日,但由于它深入参与了PHP的各个领域,并且每天通过完整的收件箱暴露于质量最低的领域,因此我了解了我们现在所处的位置以及未来的发展方向。 但是,一切都不是黑的-诸如Heroku和DigitalOcean之类的解决方案将使人们可以运行最新版本PHP和自定义版本PHP,而其价格可能比共享托管服务提供商的价格低(或更低)。

My sincerest hope is that the core team will manage to iron the new Zend Engine out to such a degree that it retains backwards compatibility with ALL extensions, but giving warning pings on compilation to all extension developers who fail to adhere to NG’s regulations and best practices.

我的最真诚的希望是,核心团队将设法淘汰新的Zend Engine,使其保持与所有扩展的向后兼容性,但向所有不遵守NG法规和最佳实践的扩展开发人员发出警告编译提示。

内部慢度 (Internal Slowness)

The core dev group is infamous for being slow to adapt to change. Modern features that existed for years in other languages were voted against in the past, only to be implemented years later.

核心开发人员小组因适应变化缓慢而臭名昭著 。 过去,使用其他语言存在多年的现代功能遭到了反对 ,直到数年后才实现 。

Whether this is because the core dev team is simply without vision, like Anthony’s and Phil’s posts say, or because it’s too small and underfunded to make any major changes at a rapid pace is irrelevant – the internal slowness means we might never see NG out in the open and out of “alpha” status, much like the case was with the mythical PHP6.

这是因为像Anthony和Phil的帖子所说的那样,核心开发团队只是没有远见,还是因为它太小且资金不足而无法快速进行任何重大更改是无关紧要的–内部的缓慢意味着我们可能永远不会看到NG打开和退出“ alpha”状态,就像神话PHP6一样。

This brings us to the last point.

这将我们带到了最后一点。

晚到党了……再次 (Late to the Party… Again)

Due to the inherent slowness often witnessed in the PHP core development group, by the time NG is implemented (if ever) all it will offer is a performance upgrade. By then, Hack with HHVM which is leaps and bounds above the standard PHP already will offer so many additional features, the race will be rigged and PHP won’t stand a chance.

由于在PHP核心开发小组中经常会看到固有的缓慢性,因此在NG实施时(如果有的话),它所提供的只是性能提升。 届时,HHVM超越了标准PHP的步伐,Hack将会提供许多额外的功能,这场竞赛将被操纵,PHP将没有机会。

Type hinting, available today in both Hack and Zephir, will have grown roots in those implementations. Multithreading, compilation, standalone web server – all features available today in alternative solutions, and all of them almost production ready. While the core dev group is working on some of those, and PHP will probably have IIS support way before HHVM (which is, apparently, important to some people), I personally still believe this isn’t nearly enough rapid progress from the official side of PHP.

如今,在Hack和Zephir中都可以使用类型提示,这些类型提示已经植根于这些实现中。 多线程,编译,独立的Web服务器–替代解决方案中目前提供的所有功能,几乎都已准备就绪。 虽然核心开发小组正在其中一些工作上,并且PHP可能在HHVM之前具有IIS支持方式(这对某些人来说显然很重要),但我个人仍然认为,从官方角度来看,这还远远不够快PHP。

Even if the core group does decide to vote “yes” on all these exotic features for which issues and demands exist, it’ll take them far too long to implement – and they’ll be late to the party by default, unless a paradigm shift is introduced and their entire way of working is turned around. Moving the source to GitHub was a good move, but it only scratched the surface.

即使核心小组确实决定对存在问题和需求的所有这些奇特功能投票“是”,实施起来也将花费太长时间–默认情况下,它们将晚于党,除非有范例引入轮班制,改变了他们的整个工作方式。 将源代码移至GitHub是一个不错的举动,但这只是表面上的事情。

That said, Rasmus himself supposedly said HHVM becoming PHP’s core engine in a few years isn’t that much of a Sci-Fi scenario.

话虽如此,拉斯穆斯本人也曾说过HHVM在几年内成为PHP的核心引擎并不能算是科幻场景。

结论 (Conclusion)

Facebook-related ownership aside (which carries with itself plenty of negative connotations on its own), HHVM pushed the devs in the right direction by showing how such upgrades can be done. This drives innovation and forces those who have been comfortable in their throne for too long to get up, stretch their legs and see if they can still run. Facebook’s aggressive approach forced the PHP world to do a double-take and wonder about what’s going on, and soon enough it caught on.

除了与Facebook有关的所有权(本身具有很多负面含义)之外,HHVM还通过显示如何进行升级来将开发人员推向正确的方向。 这推动了创新,并迫使那些在宝座上坐了太久的人无法起床,伸直双腿,看看自己是否还能跑步。 Facebook的进取态度迫使PHP世界进行了两次尝试,并想知道发生了什么,很快就流行了。

Competition is awesome. Wherever this takes us next, I’m optimistic about it.

竞争真棒。 无论接下来将我们带到何处,我对此都很乐观。

文章更新,2014年5月28日 (Article update May 28th, 2014)

After an email exchange with Phil Sturgeon, and after reading the official statement, I have edited parts of the above text. In short, I classified PHPNG as a JIT, when it is clearly not that, but a mere performance upgrade that will allow the core group to develop a proper JIT compiler later on.

与菲尔·斯特金(Phil Sturgeon)进行电子邮件交流之后,并阅读了官方声明之后 ,我编辑了上述文本的部分内容。 简而言之,我将PHPNG归类为JIT,但显然不是这样,而仅仅是性能提升,这将使核心小组以后能够开发合适的JIT编译器。

翻译自: https://www.sitepoint.com/php-fights-hhvm-zephir-phpng/

php hhvm



推荐阅读
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • ShiftLeft:将静态防护与运行时防护结合的持续性安全防护解决方案
    ShiftLeft公司是一家致力于将应用的静态防护和运行时防护与应用开发自动化工作流相结合以提升软件开发生命周期中的安全性的公司。传统的安全防护方式存在误报率高、人工成本高、耗时长等问题,而ShiftLeft提供的持续性安全防护解决方案能够解决这些问题。通过将下一代静态代码分析与应用开发自动化工作流中涉及的安全工具相结合,ShiftLeft帮助企业实现DevSecOps的安全部分,提供高效、准确的安全能力。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了使用PHP实现断点续传乱序合并文件的方法和源码。由于网络原因,文件需要分割成多个部分发送,因此无法按顺序接收。文章中提供了merge2.php的源码,通过使用shuffle函数打乱文件读取顺序,实现了乱序合并文件的功能。同时,还介绍了filesize、glob、unlink、fopen等相关函数的使用。阅读本文可以了解如何使用PHP实现断点续传乱序合并文件的具体步骤。 ... [详细]
  • 本文讨论了Kotlin中扩展函数的一些惯用用法以及其合理性。作者认为在某些情况下,定义扩展函数没有意义,但官方的编码约定支持这种方式。文章还介绍了在类之外定义扩展函数的具体用法,并讨论了避免使用扩展函数的边缘情况。作者提出了对于扩展函数的合理性的质疑,并给出了自己的反驳。最后,文章强调了在编写Kotlin代码时可以自由地使用扩展函数的重要性。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 本文介绍了django中视图函数的使用方法,包括如何接收Web请求并返回Web响应,以及如何处理GET请求和POST请求。同时还介绍了urls.py和views.py文件的配置方式。 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • React基础篇一 - JSX语法扩展与使用
    本文介绍了React基础篇一中的JSX语法扩展与使用。JSX是一种JavaScript的语法扩展,用于描述React中的用户界面。文章详细介绍了在JSX中使用表达式的方法,并给出了一个示例代码。最后,提到了JSX在编译后会被转化为普通的JavaScript对象。 ... [详细]
  • 本文介绍了在使用Laravel和sqlsrv连接到SQL Server 2016时,如何在插入查询中使用输出子句,并返回所需的值。同时讨论了使用CreatedOn字段返回最近创建的行的解决方法以及使用Eloquent模型创建后,值正确插入数据库但没有返回uniqueidentifier字段的问题。最后给出了一个示例代码。 ... [详细]
  • Tomcat安装与配置教程及常见问题解决方法
    本文介绍了Tomcat的安装与配置教程,包括jdk版本的选择、域名解析、war文件的部署和访问、常见问题的解决方法等。其中涉及到的问题包括403问题、数据库连接问题、1130错误、2003错误、Java Runtime版本不兼容问题以及502错误等。最后还提到了项目的前后端连接代码的配置。通过本文的指导,读者可以顺利完成Tomcat的安装与配置,并解决常见的问题。 ... [详细]
author-avatar
蔡少暖_171
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有