7 ms·
Taking PHP Seriously
- Kiro 13y agoPrevious discussion: https://news.ycombinator.com/item?id=7054294 https://news.ycombinator.com/item?id=7054294
- Nilzor 13y agotl;dr what is HHVM and why should I care as a PHP developer?
- philo23 13y agoHipHop Virtual Machine, it "compiles" PHP into C++. Though it needs to be written in a certain way to work correctly as I understand it.
- unfunco 13y agoIt doesn't need to be written in a certain way, there may be new features in recent releases of PHP that don't work on HHVM but the HHVM folks are pretty quick to add in support for those features. Here is a little library[0] I wrote in PHP and this is tested on HHVM using Travis (see .travis.yml). I haven't had to write the PHP any differently, it just works (although it's an incredibly small library). Edit: The speaker in the video also mentions that they have taken the test suites from the top twenty PHP projects and they test them against new releases of HHVM, further confirming that the syntax requires no special attention except for new language constructs. [0] https://github.com/unfunco/bijective https://github.com/unfunco/bijective
- drdaeman 13y agoYou're mistaking HHVM with HPHPc. They're both Facebook projects and one grew inspired by another, but they use different approaches.
- tscherno 13y agoIt`s a jit-compiler for PHP. Code is compiled once to an intermediate representation (like Java) which makes execution faster on subsequent request. Code does not have to be written in a certain way most of the time because hhvm is 98% compatible to all major PHP-Frameworks[1]. It also features a built-in webserver alltough static performance is lower than nginx. [1] http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16 http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16
- agumonkey 13y agoSomehow an asm.php
- plextoria 13y agoNo, it does not compile to C++, but to bytecode. HHVM's predecessor converted PHP to C++, though.
- blowski 13y agoWhat's the difference between that and APC? The performance, or is there something else? Confession: I haven't listened to the OP yet.
- RossM 13y agoIt's an alternative PHP runtime. It no longer compiles PHP to C++ (it's predecessor hphpc), instead it uses a JIT compiler which gives it better performance over standard PHP, without requiring a compilation step. It's mostly compatible with the standard PHP syntax/stdlib. It offers an alternative syntax that allows you to give return types of functions, which can give you further speed improvements. There's also a few additional features (for example, it supports similar hinting to the recent ArrayOf RFC). It's worth checking out, but probably not worth using in production yet - they're working on getting the top 20 frameworks to pass their unit tests in HHVM[0], so there's a good chance your existing apps will run. [0]: http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16 http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16
- bovermyer 13y agoPhalcon is noticeably absent from that list. Do they have any intention of supporting that, too?
- thejosh 13y agoUnless you are running something custom/unsupported, if you are using nginx/php-fpm you can just replace it with the HHVM FastCGI and get it to run your code really really fast. It's great as it makes everything run a lot quicker for clients who use PHP, especially if you have code that needs to be run in PHP on the command line. Just run it and see :).
- madsushi 13y agoWell, it doesn't support mysqli_, which is a very common family of functions, especially since mysql_ is being deprecated. But a lot of stuff does run, as long as it doesn't need mysqli_.
- NigelTufnel 13y agoGoing JIT seems to be the common way of the scripting/bytecode-compiled languages. Java -> HotSpot, Python -> PyPy, Javascript -> V8 and friends, PHP -> HHVM
- pjmlp 13y agoLisp and Smalltalk were the first ones.
- lispm 13y agoMcCarthy is mentioned for that, but I guess more work on that was done in the Smalltalk and Self context. Since quite some time most Lisp systems don't use a JIT. They compile the code ahead of time or explicitly incrementally.
- pjmlp 13y ago> Since quite some time most Lisp systems don't use a JIT. They compile the code ahead of time or explicitly incrementally. I am aware of type hints, but given Lisp's dynamic nature, wouldn't a JIT provide more optimized code than AOT?
- smoyer 13y agoWith an optimizing compiler to boost its performance, I think PHP would still benefit from two things: 1) A resource like "PHP - The Good Parts", that guided developers through the dos and don'ts of the language at an early stage. 2) An overlay language (like Coffeescript over Javascript) that effectively hides the bad parts, but that might also be extended to bring some consistency to the library APIs (even a bunch of aliases that used consistent naming rules would help). I'll admit that I have written anything serious in PHP since the late '90s but those are the issues we had bring new developers up to speed.
- RossM 13y ago1) sort of exists in http://phptherightway.com/ http://phptherightway.com/ 2) There's been a couple of these, most recently Mammouth[0], but personally I don't think that's useful - the syntax is more or less OK. I do think that renaming the core functions and then providing an alias/compatibility library would be beneficial however. Personally, the most inviting part of HHVM for me isn't the performance, it's the alternative team that seem willing to develop the language more in-line with what users want. [0]: https://github.com/btwael/mammouth https://github.com/btwael/mammouth
- martinml 13y agoAlso about 2), haxe: http://haxe.org/doc/start/php http://haxe.org/doc/start/php
- gedrap 13y ago>>> I do think that renaming the core functions and then providing an alias/compatibility library would be beneficial however. Totally agree with that. In the real world, one is normally using some sort of framework which hides most of the language quirks (inconsistent naming, order of parameters, etc). And the cases, when you need to use quirky native functions, are rear enough so that introducing additional layer where bugs might occur is not beneficial enough. So I'd focus more on picking the right framework (both philosophically and technically) rather than on focusing on a new language. Why I mention frameworks that much? Because in the of majority cases, applications are just some CRUD with a bit of logic and going with flat php + some home made libraries is just waste of time.
- mjohan 13y agoWhat is different from the intermediate code HHVM generates and the code that OPcache/apc stores? Is HHVM always faster compared to code that is cached in OPcache/APC?
- martinml 13y agoAn opcache code just stores the bytecode so you just avoid the parsing step in each request. It does not inherently optimizes anything, although it has been tried with APC in the past (but finally abandoned). I don't know what's the status with the new official opcache and optimization.
- riffraff 13y agoif you are discounting this discussion on account of not being interested in the VM consider it's also quite interesting for the way they changed the language. E.g. gradual typing with type inference, generics, closures, nullable types, generators and a lot of static checks and removals of "arguably dumb" php features.
- Xdes 13y agoIt would be nice if they just reinvented PHP. Get the top 20 major frameworks behind them and fork it.
- deleted 13y ago[deleted]
- test1235 13y agoThat would probably result in the same situation as what we have with Python 2 and 3.
- acdha 13y agoThey're proposing essentially that: start at the 24th slide http://www.slideshare.net/zerutreck/taking-php-seriously-keith-adams http://www.slideshare.net/zerutreck/taking-php-seriously-kei... The smart part is that it's opt-in so you could gradually migrate a large project in-place. The only question would be whether they've broken compatibility with standard PHP or if it's simply stricter — it'd be really easy to get major projects to switch if it was like JavaScript's "use strict" where you can develop in strict mode but run on a legacy runtime.
- Xdes 13y agoI'll have to take a look at the Hack language. I've always wanted to try PHP, but I've always been deterred by the cruft (same reason I avoid Java).
- untilHellbanned 13y agoIs there a "how to" in using this with PHP framework X? Perhaps HHVM just need to be installed and then a change to your Nginx/Apache config needs to happen? Serious kudos to FB and the developers who are making this happen!