PHP mascot, looking forward to PHP 7

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.

Phpng

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

PHP 7

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?

JIT Engine

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.

Asynchronous Programming

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:

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…

PHP 7, PHPNG and the future of PHP

7 thoughts on “PHP 7, PHPNG and the future of PHP

  • December 22, 2014 at 12:28 pm
    Permalink

    Compared to other web languages that require a
    bit of study, PHP does not require one to spend a lot of time researching a
    manual. Thanks to the syntax being logical and command functions describing
    exactly what they do, one can easily get right to the part of creating and
    optimizingthe application.If you have programming experience in both Perl and
    C, then learning PHP will be quite easy, as its syntax is based on these
    languages.Since PHP is an open source web language(http://cedarsoftware.co.uk ), it’s completely free of
    cost.Depending on how you code, PHP can turn out to be an efficient web language
    to use. In fact, PHP is known to be scalable when writing code as well as in
    creating applications and is very reliable when you need to serve several web
    pages.If you get stuck or are getting started when using PHP, one of the best places
    you can find information about the language is php.net apart from php
    pros from numerous websites and forums that are available over the internet.

    Reply
  • February 6, 2015 at 12:35 pm
    Permalink

    PHP is an open source server-side scripting
    language specially designed for developing web application. Currently, about
    80% of websites uses PHP. Having responsive website will ensure added advantage
    to your business organization. PHP Training center Chennai

    Reply
    • February 6, 2015 at 1:36 pm
      Permalink

      While it is true that a large number of websites run using PHP (I doubt the number is 80% though), PHP is not the sole contributor to responsiveness on the world wide web. Most of the technologies currently in use on the net such as .NET, python, java, etc. are all responsive. The important thing to note is that a language in and of itself will not provide high performance. The way it is used, the underlying server and application stack as well as the quality of code will contribute immensely to the responsiveness of a website / web application.

      Reply
  • July 30, 2015 at 2:44 pm
    Permalink

    Of course, but someone will fork wordpress and utilise HHVM only features, that fork will no longer run onPHP. Future developments and plugins will then be tied to a specific fork causing fragmentation
    For more details : http://www.thinkittraining.in/php-training

    Reply
  • July 30, 2015 at 2:54 pm
    Permalink

    It’s all unnecessary. What needs improvement is programming skill. Done right, PHP doesn’t need any of this crap. Layer upon layer to do what could be done natively by someone with the proper skills. Lower complexity; stop trying to be Java

    for more details : http://www.attendasoft.com/php-training-in-chennai

    Reply

Your Thoughts: