HipHop and the Future of PHP Development
A couple of weeks ago I read an interview with an anonymous Facebook employee, who claimed that their engineers had 'rewritten' PHP into a compiled language, dubbing the result 'Hyper-PHP'. My interest was piqued, especially as the employee further declared that pages would load in a fifth of the time when delivered through this 'PHP executable'. That's no small improvement. I looked around for more information on 'Hyper-PHP', but found nothing aside from reaction to the article, which was mostly dismissive. There was no mention of anything concrete on the PHP Internals list, Twitter, or the blogosphere. Thinking it unlikely that a development this massive in the PHP language could occur without some information leaking out, I reluctantly assumed that the employee was either being sensationalist, or was somehow mistaken.
I was therefore quite excited when the rumour turned out to be true.
Now that some details have emerged about HipHop, as it's been named, can offer a PHP application, I'd like to offer some thoughts on how this will affect developers writing web applications now and in the future.
Firstly, it's clear what HipHop's benefit is: a gain in performance. However unlikely, as Sebastian Bergmann notes, that the majority of today's PHP applications find their bottleneck at the CPU level, it is nevertheless a concern or Facebook wouldn't have had to solve it. At the moment there are few, if any, web applications dealing with the sort of problems that Facebook are; in the future this will almost certainly change. Not only as a result of increased internet usage as more people are able to access the web, but also as more traditionally desktop-based applications move to the cloud, in the same way word processors and email recently have. With this increased complexity we will likely see more strain being placed on the server, which is where developments like HipHop become vitally important.
A more immediate consideration is that HipHop is also important to PHP as a language. Facebook's innovation goes a long way towards eliminating the old argument against adopting PHP - that compared to strongly typed, static languages such as Java, it is comparatively slow and thus a less suitable choice for a high-performance, enterprise-level application. With this admitted weakness now combated by HipHop through its conversion of source code from 'slow' PHP to lightning-fast C++, we have the scenario where the PHP language not only has one of the lowest barriers for entry, but also ranks as one of the most efficient and powerful options to a developer. PHP developers are now set free to write complex, sprawling, well structured applications in the Java mould without having to fear a performance penalty in the future.
There are caveats, of course. During Facebook's tech talk which served as an introduction to HipHop, lead engineer Haiping Zhao noted that some language features, such as 'magic' methods, could not be evaluated by their transformer and would run at normal PHP speed. Therefore the more 'magic' an application, the lesser HipHop's impact will be. As PHP is such a weakly-typed language, which deliberately makes it easy for developers to express themselves with as little specification as possible, not all applications will see a benefit without sacrificing freedom for explicit code. PHP already allows for type-hinting in method arguments for objects and arrays; the recent clamour to extend this to scalar variables and introduce a similar feature for return values now takes on added significance.
In addition to this, some functions like eval() and create_function() aren't even supported; while there are always alternatives to using them, and in eval()'s case an alternative is often advised, a lot of PHP applications make use of them, especially the older ones. We used eval() recently to fake a class inheritance hierarchy. So an application wishing to make use of HipHop will at the very least have to consider their use of language features from the outset, or potentially rewrite some of their codebase to make it compatible. For this reason, from this moment on it makes sense to keep HipHop in mind from the start, rather than produce an application only to later find that a complete rewrite stands in the way of an integration.
Facebook have stated that HipHop is currently only able to process the 5.2 version of PHP, with 5.3 support 'coming soon'. This obviously rules out applications using earlier versions, but potentially also those that utilise third-party libraries, like templating engines or utlilties, which may make use of unsupported features or extensions. Developers are often warned against the 'Not Invented Here' syndrome, and in almost all cases it makes sense to use existing code rather than reinvent the wheel - but what if that code is not compatible with a tool that can double your page view capacity? If an update to the library to make it compatible is not forthcoming, a trade-off surely has to be made. HipHop also currently runs exclusively on *nix, which alienates a significant number of Windows-based applications.
So HipHop isn't a silver bullet. But it is a significant achievement because it not only dramatically increases PHP's power, but more importantly proves that PHP is able to support and adapt to the needs of arguably the most prominent web application in the world. With a preeminent company like Facebook raising PHP's profile, improving its effectiveness, and releasing their work back to the community, PHP's future is seemingly assured.
The Amaxus Content Management System offers a sophisticated feature set, across hundreds of highly-configurable modules; all within the most usable Web CMS interface available.

0 Comments