July’s PHP London had a particularly notable speaker – Rasmus Lerdorf himself presenting what’s new in PHP. So many people wanted to attend that, with limited venue capacity, a live (and recorded) video stream was used for the first time. You can skip straight to seeing the slides and video of the session if you like, or keep reading for my impressions of the evening.

PHP History & Evolution

The story began in 1993, when the web was made in C/C++ and Perl. Rasmus initially created PHP as a tool for himself; at first it was written in Perl and only later converted to C for performance.
For a bit of nostalgia, visit the PHP Museum grab one of the first versions, compile and see for yourself how it looked and felt back then.
The talk got even more interesting (and non-standard) when Rasmus mentioned a few things that were introduced then and still confuse programmers today:

  • Case insensitive function names. The dilemma came from the days when there were flame wars whether HTML tags should be lower or upper case, at that time the scripting languages were rather tightly coupled to the web pages themselves and so the choice was left to the developer to follow either practice.
  • Function name inconsistencies. There is no standard because functions came into PHP from many different places: some of them are direct mappers to C functions, so names were persisted; some others come from specific libraries, so remain consistent with the library’s naming those names were kept. These days it is a rule not to have any rules (other than common sense) on function naming in PHP.
  • $ sign for variables. If you have a tiniest bit of experience in compiler (or at least parser) writing, you will understand how much simpler it is by using a special character. It started as a quick hack and now it’s stuck there for good, and it helps readability.
  • Globals. It was by choice that functions are limited to the local scope and you can use global scope variables only by explicitly stating so; Rasmus is proud of getting it better than other languages.
  • register_globals. In the early years of PHP, it was used a lot like a templating language making a form variable readily accessible in the file made it useful to a wider audience. The language has long grown out of this stage and as a result this parameter is removed as of version 5.4.
  • $haystack-$needle or $needle-$haystack? This is one thing that drives many new developers crazy, but there is a pattern. All string functions are haystack-needle, and all array functions are needle-haystack!

Notes on PHP 5.4

Rasmus then moved on to modern days the latest versions of PHP; it’s been over a year since PHP 5.4 was released in March 2012, at this point it is considered mature and reliable, Rasmus stressed repeatedly that you should be using this version in production today. PHP 5.4 brought great performance improvements but introduced hardly any changes that break backward compatibility, so there is little effort needed to upgrade your codebase. To illustrate his point, Rasmus showed benchmark graphs of how servers performed for Etsy when they were running PHP 5.3 with APC , and when they were using PHP 5.4 with OpCache. With no code changes whatsoever they got 10-15% better performance in terms of memory usage and latency.

With these results, he accused anyone, who has not upgraded yet, of simply not doing their work, so after you are done reading this article, please go and upgrade your servers!

PHP 5.5: Shiny and New

At this meeting, PHP 5.5 was merely 14 days old, so it was a really hot topic. This new version brings us some further performance improvements and assorted new features, but there are three things worthy of a special highlight:

  • Password hashing API. In order to make secure password handling easy, we now have two core functions: password_hash() and password_verify(). Now even the “weekend warrior” (Rasmus’ words) can easily get this right.
  • Generators. You can now have virtual iterators that generate the next value on-demand rather than pre-allocating all the elements in advance. It uses the new yield syntax to allow a function to return values on each call.
  • Finally block. Our existing try-catch construct is now try-catch-finally. You could hear the audience reaction to this: “Finally!”.

PHP 5.5 is the best of PHP to date, and remember the built-in web server – you don’t need to reconfigure your whole server just to play around with the newest PHP.

Atomic PHP deployments

The last part of the presentation went to introduce a risk-averse deployment strategy and some tools to help make this possible. The Engineers at Etsy (Rasmus’ current employers) have developed both an Apache module named mod_realdoc and a PHP extension, incpath. The idea behind it is to point your Apache’s document root to a symlink and allow it to look up the actual path before the script execution and only once for the whole execution. This way, you deploy your new code in a separate directory and, when ready, just switch the docroot symlink to point to the new directory. You are guaranteed that all requests that started with the old files will continue with the old files until their process termination, while all new requests will run only the new code. This means that your application cannot perform any realpath lookups itself, and incpath is there to help with this and with getting include paths correct.

Conclusion (a.k.a. TL;DR)

PHP has gone through 20 years of evolution. It is now as good as ever and continues to improve, both for enterprise applications and for use of the “weekend warrior”. Anyone still using PHP 5.3 or earlier is seriously missing out on performance and features which are ready to be used. Upgrades are straight forward, needing minimal effort and producing significant gain. So you should go and upgrade your systems to 5.4 today – and tomorrow install 5.5 to play around and test forward-compatibility of your codebase. If you get stuck, Inviqa consultants can assist with an upgrade.

The slides from this session are available at talks.php.net and the video is on PHP London’s Ustream channel.