PHP
Article

PHP7 Resource Recap

By Bruno Skvorc

PHP 7 is well on its way. RFCs are being implemented and polished, projects are being tested, libraries upgraded. Extensions are being modified, and the word is spreading. All that remains is getting the shared hosts on the upgrade bandwagon – the arguably most difficult part of improving the global state of PHP. In this article, we’ll take a look at some of the most important PHP 7 related resources and tips you should go through in preparation for the new version.

Php7 logo by Vincent Pontier

Image via Vincent Pontier

Rasmus’ box

Some months back, Rasmus Lerdorf created and uploaded a Vagrant box for testing on PHP 7. This box can be downloaded from Github. In case the instructions are confusing (they shouldn’t be), see Rob Allen’s post. The box boots up in minutes and has not only PHP 7 enabled, but can also very easily update to the most recent version of PHP 7, and to dozens of other PHP versions.

The box features a newphp command which instantly replaces the PHP version currently in use with another binary, pre-compiled on the box. So for example, typing newphp 55 in the box will switch from PHP 7 to PHP 5.5., allowing you to quickly run your code in another version. What’s more, each version has its own PHP extensions folder, so you can easily compile and install new extensions – they all end up in the right location, and won’t conflict with other PHP binaries.

In a way, it’s similar to DUnit which uses Docker containers to fire up different PHP versions for you to test on.

For more information and some interesting benchmarks of various CMSes from Rasmus himself, see this talk slideshow of his.

Other boxes and Testing

You should test your code on PHP 7. Early benchmarks are promising and many are jumping on board. Some even tested their real world apps and got some impressive results.

Use Rasmus’ box above, or if you’re using PuPHPet, they recently added PHP7 support. There are some caveats, but in general, it should work. Vaprobash and Phansible aren’t there yet, but here’s hoping.

If you’d like to roll your own, this Ansible playbook for Ubuntu / Debian might help, or just go full-shell and follow these instructions – the post also has tips on writing tests for the actual PHP build, so you can contribute to the language itself!

If you don’t feel like firing up VMs, you can use some of the official nightly builds (also supported via Docker) from Zend, but it’s also quite easy to do in Travis, which now includes PHP 7 in its builds. In fact, the phpleague/skeleton has this built-in. Just remember – if you’re using the Travis results to power Scrutinizer’s code analysis – you should allow failures on PHP 7 and maybe even make sure the report for PHP 7 doesn’t get submitted at all.

Testing for PHP7 on Travis not only makes sure your code works on the latest nightly without forcing you to manually update your PHP7 build, but also gives you some street cred to brag with – “My code is PHP7 ready!”.

Updating Extensions

Libraries, packages and apps aren’t the only that need testing, though. Like the March Newsletter said (to which you can subscribe via this form, btw), extensions are on the front lines. PHP7’s new extension API is different enough from the old versions that several extensions will need extensive rewrites to remain compatible.

With that in mind, the gophp7-ext page has been set up to ease the transition for most extension developers.

Hopefully, this will make it easier for projects like Zephir and the newly released Phalcon 2 to become 7-friendly as soon as possible (as the Phalcon team says, they’re already looking at the necessary PHP7 upgrades).

If you develop PHP extensions (maybe you started after reading some of our tutorials?) or know people who do – point them to the GoPHP7-ext page and have them bring their code up to par. If you can get them to write about the process, documenting the changes that needed to be done, please do point them my way and we’ll publish their findings (and pay them handsomely for them), so others can benefit from learning about the process.

Important Reading

Finally, let’s list some of the most important reading resources you should go through to get on top of the changes that are coming up.

  • Phil Sturgeon got the ball rolling with his post about the PHP7 feature freeze and the current state. It lists some of the more important RFCs, but you should look below to Davey’s post for a more detailed overview.

  • What to Expect is the first post you should read. It’s a two-part series from Davey Shafik, which explains the upcoming changes in a down-to-earth way. It’ll list all the important accepted RFCs and display demo code for each, so you can see how they might affect your workflow on practical examples.

  • PHP7 at a Glance from none other than Zend is yet another excellent overview. It features all the RFCs listed with their potential impact on a developer’s life plus the chances of BC breaks (there are some in edge cases, but none certain).

  • Comparing PHP7 and Hack type systems implements the same functionality with type hints (now that they’re coming to PHP) in both PHP7 and Hack. The differences may surprise you, and might be something worth keeping in mind. The post has been discussed on Reddit.

  • If you’re confused about the strict types, this still relevant post breaks it down.

  • PHP7 Revolution – Return Types and Removed Artifacts is our own preliminary look at PHP7 from way back when the announcement was still hot off the press. (Link added May 14th, 2015)

Performance stats

  • Zend put out this impressive looking infographic on performance. It doesn’t have the benchmarked source code or the environment details, though, so take it with a grain of salt. (Link added May 14th, 2015)

Wrapping up

As you can see, there’s a lot of content to go through – and version 7 is still months away. We’ll be updating this list with new resources periodically, so make sure you check back from time to time – newly added posts will be put to the bottom of their respective list and tagged with the date of addition.

Do you know of any valuable resources we’ve missed? Want to write something for us? Let us know!

Comments
TaylorRen

Just the right timing!

s_molinari

Nice post Bruno! I am not too sure I'd want to brag my code runs on PHP 7 though. Although it is tempting. LOL! smiley

What interests me the most are the large performance gains and smaller memory footprint per request. That is something almost worth bragging about. smile

Would you say the performance is so good, a JIT compiler isn't going to do much more? Or can there still be an improvement in performance with a JIT compiler? I noticed in the benchmarks PHP7 is comparable to HHVM, but what is never mention is if the HHVM JIT compiler is on or not and if not, what are the differences then? If the HHVM JIT is on, oh my. I am impressed.

Scott

s_molinari

Ok. I just read one of the articles you linked to and the author said PHP7's performance is on par to HHVM with the JIT compiler working. Now the question in my mind is, would having a JIT compiler help with performance or with the memory footprint.

Scott

swader

It probably would help, yes, to a degree. But I think the focus now deserves shifting from performance to some more pressing matters. At these speeds, it's almost impossible for PHP to become the bottleneck. But making the built-in server a viable Apache/Nginx replacement - now that's something I could see as downright revolutionary.

s_molinari

I've been playing with Appserver.io lately. They do just that. wink

Scott

swader

Yes, it's been on my list for a while, need to check that out again. We've had a brief look a long time ago but I definitely want to dive in deeper and deploy something proper on it.

s_molinari

I also read that article. Appserver has come some way since then. Installation was a breeze and I am wrapping my head around how to use the beans, servlets and other services. If you ask me, it is like a very light PHP framework on steroids.

Scott

swader

Nice, looking forward to it!

s_molinari

Actually, "on steroids" is the incorrect way to express what Appserver represents. It is more like a lightweight framework that allows PHP to be what it actually needs to be.

Edit: Here is an interesting video on Appserver.

Scott

TomB

Interesting, after Michael Morris's post here about mark_script_ready() I built a PHP app server. (In my limited tests so far it's 500% faster than not using the app server on a non-trivial application). Essentially, when you connect to the server via HTTP, Apache/NGIX/whatever all that does is run a minimal script that does nothing except connect to the app server and request the state rather than construct all objects, connect to the database then shutdown.

So far I've got great concurrency (it runs a server on each available thread) and maintains persistence so if your code does $num++ each time you visit a page $num goes up without getting reset.

s_molinari

Which basically means, you can do different things at different times, instead of doing it all with each request. As Stefan points out in the video above, with Appserver, you don't have to run any bootstrapping scripts with each request. You can store such things (and many others) as a servlet, which start running at server startup and stays in memory until the server is stopped or restarted. It is sort of akin to the Tomcat web server for Java, from what I can tell.

Scott

TomB

I've just put a post up in showcase with my implementation smile Take a look at the code, it's surprisingly simple!

Wolf_22

With something like that, are you saying that instead of going through the normal steps of installing Apache and then PHP, you would just have one simple install of PHP only? In your mind, how would all of that fall into place from the perspective of shared usage?

swader

Relevant?

Actually, more relevant, in particular this.

swader

Additionally, this from Reddit.

/cc @TomB

s_molinari

And this and here is PHP-PM, which Fabien mentions.

Edit: Could you imagine what you have with PHP7 and all this? Buuahahahahaaha! smiling_imp

Scott

alexbelly

hahaah PHP7 and java script, going to be marvelous

prequel

PHP 7 is wonderful. I am using Centmin Mod LEMP web stack auto installer for running my Wordpress 7 blog, it already has support for PHP 7.0.0-dev from git source https://community.centminmod.com/threads/php-5-7-phpng-support-testing-for-centmin-mod-betas.892/ smile

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in PHP, once a week, for free.