There is some confusion regarding the next major version of PHP. Although original slated to be called PHP 6, the developers have reached a consensus that they are going to skip version 6 and go straight to PHP 7. On the surface this might seem like an illogical step, but on further examination, it makes a lot of sense. An RFC was submitted to debate this decision. After a closely and hotly contested debate, it was decided that it was best to skip version 6. Let me try and shed some light on the events that led up to this decision.
History of PHP 6 vs PHP 7
Plans to release PHP 6 started a very long time ago. In fact development started around the year 2005. The main goal was to achieve full unicode support within PHP which, in hind sight, was too ambitious. After more than 4 years of development, the initiative was abandoned. Meanwhile many of the changes that were developed during this time were isolated from the PHP 6 branch and merged back to PHP 5 in subsequent releases within versions 5.4, 5.5 and 5.6. But by then numerous books, tutorials and pages on the internet emerged purporting to teach PHP 6. A search for PHP 6 will reveal a lot of outdated information in search engine. This was partly the reason for the proposal of skipping directly to version 7 as the next major PHP version.
HHVM and Zephir
Meanwhile, Facebook, frustrated with the slow down in the pace of development and non-existent performance improvements in PHP, churned out HipHop. HipHop, a PHP transpiler, was later deprecated in favor of HHVM. HHVM and Zephir are two solutions that are currently used in order to improve the performance of PHP. HHVM is promoted by Facebook where as Zephir is entirely open-source.
HHVM is a Virtual Machine replacing the Zend Engine that makes use of Just-in-time compilation to achieve better performance. Zephir allows a developer to create libraries and procedures that are pre-compiled and callable from PHP scripts. This way, Zephir provides benefits of both compiled as well as interpreted languages. Both these solutions tackle the performance problem in exciting and different ways. The guys at Facebook even introduced a new language called Hack specifically for the HHV. Currently, PHP runs fine on it save for some exceptions such as the eval() function.
Since PHP 5.4, the performance and memory footprint of PHP as a whole has been steadily improving. In PHP 5.5, the opcode cache was pushed into the mainline code providing performance boosts for all at virtually no additional effort. The jump in performance from PHP 5.3 to PHP 5.4 is especially noticeable. But as PHP, and the world wide web in general, is growing more and more, developers are always on the lookout for even more performance. As a result of this thirst for high-performance coupled with the advent of HHVM and Zephir, the phpng branch was created to improve the performance of PHP. As of this writing, this branch is now merged with master and confirmed for the next major PHP release.
As more and more development went into phpng, an RFC was created to vote for using phpng as the basis for the next major version of PHP and passed almost unanimously. The word on the street is that phpng is quite fast and in some cases even beats HHVM by upto 20% in it’s performance! But how did they achieve such huge improvement in performances? To quote Dmitry Stogov, the main moving force behind the project:
“It was clear the VM is already highly optimized, but works with data structures that require endless memory allocation, deallocation and reference counting. Typical real-life PHP application spends about 20% of the CPU time in memory manager, 10% doing hash tables operations, 30% in internal functions and only 30% in VM.”
This brings us to PHP 7. As we learned just now, PHP 7 will feature all the improvements in the phpng branch. But what else can we expect from the upcoming major version of PHP?
A JIT engine for the Zend Engine is currently being worked on. This will allow the Zend Engine to dynamically compile Zend opcodes to native machine code. This will in turn allow subsequent calls to the same code to run a lot faster. According to Zeev Suraski, it can “push performance through the roof for an already ultra fast implementation“.
Abstract Syntax Tree (AST)
Nikita Popov proposed the introduction of an Abstract Syntax Tree (AST) as an intermediary structure in PHP compilation process. An AST would provide several advantages that he described in his proposals, including the potential for more optimizations that would make PHP run even faster. In the latest proposal he describes the possibility to expose the AST to PHP extensions and userland applications. That could open space for more interesting tools like static code analyzers which are often useful to detect bugs or potential source level optimizations of your PHP code. Nikita already provided a patch to implement AST support on top of the PHPNG branch.
Standalone Multi-threaded web server
This feature might not make it in PHP 7 version, but it is something that would make PHP more scalable. This feature is already present in HHVM which can be run as a standalone multi-threading Web server. This allows Facebook to reduce the numbers of server machines needed to handle the high traffic load.
A multi-threading Web server can handle many simultaneous requests using a single memory pool. It would also allow PHP use a single pool of database connections, thus minimizing the number of simultaneous database connections opened during access peaks.
This feature would allow future versions of PHP to easily implement support to the execution of parallel tasks within the same request. This will result in pushing performance improvement potential of PHP to the next level. Of course, we won’t get performance improvements automatically just by enabling the support for asynchronous programming. New PHP code needs to be written to take advantage of its potential.
When is PHP 7 expected to be released?
All this leaves us with the next logical question: when is PHP 7 expected to be released? It is too early to predict the exact release date of PHP 7, but Zeev Suraski tweeted this recently:
— Zeev Suraski (@zeevs) November 28, 2014
Some people say that it will take around 1 to 3 years. A reasonable guess is to expect a final PHP 7 release some time in 2016, although it is possible that we see an early alpha version of PHP 7 before that. But one thing is for sure, the future of PHP looks exciting to say the least…