php hhvm_PHP与PHPNG对抗HHVM和Zephir

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).

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值