Join Kevin Skoglund for an in-depth discussion in this video Better performance, part of PHP 7 New Features.
- View Offline
- [Voiceover] The biggest feature of PHP 7 isn't actually a feature at all. It's the fact that PHP 7 has significantly better performance than previous versions of PHP. In my opinion, this is by far and away the primary reason that you should consider upgrading to PHP 7, no matter what your circumstances, because it's much faster. PHP 7 has a number of optimizations in the way that it processes the PHP code and turns it into assembly language or machine language that your computer can understand. And it uses a lot less memory in that process.
It moves things around in memory a lot less, and that makes it faster. How much faster? It's roughly twice as fast. That's significant. This is not just a 10% increase like we've seen on some previous versions of PHP. This is twice as fast, 100% increase. That means that not only can you return pages to your users twice as fast, but it also means that a single server can handle twice as many requests because it can finish with one request and it's ready to receive a request from someone else.
And that means that data centers could need half as many servers in order to serve the same number of customers at the same speed as they did before. That's significant, and it has an impact in terms of real-world dollars. To get an idea of how much faster the two are side-by-side, Zend put together some benchmarks. So I'm going to give you a summary of some of those here. You can go to their website if you want to see the full list of benchmarks. For PHP 5.6 versus PHP 7.0, we're comparing the number of requests per second that each one can do with popular applications and frameworks.
So for example, with WordPress, PHP 5.6 could serve 191 requests per second. PHP 7 can handle 374 of the same kinds of requests per second. Drupal, 182 versus 316. Magento, 41 requests versus 69 requests. For the Laravel Framework, 256 requests versus 485. And we see something similar with the Zend Framework.
250 requests versus 489. So it depends on exactly what you're doing, but in general, PHP 7 is twice as fast as PHP 5.6. And it compares nicely with the HipHop Virtual Machine or HHVM. If you aren't familiar with HipHop, it's a PHP virtual machine with just-in-time compilation that was developed by Facebook. It processes and optimizes PHP code differently than the typical PHP Zend engine.
Until PHP 7, HipHop was much faster. Someone like Facebook obviously has a big interest in having their code execute as quickly as possible. They potentially save millions of dollars on costs if they can run their business with fewer servers. So up until now, HHVM was far and away faster than PHP, like twice as fast. But now that PHP 7 has doubled its speed, it's competitive with HipHop Virtual Machine. I've seen some benchmarks that show PHP 7 being faster and some that still show HipHop Virtual Machine being faster.
It probably depends a lot on exactly what kinds of tests you're running and on who's running the test and whether they have a vested interest in having one be more performant than the other. So let's just leave it at saying that they're now competitive with each other where they didn't used to be. And the nicest thing about all these performance gains in PHP 7 is that you don't actually have to do anything in your code in order to realize them. All you have to do is upgrade to PHP 7, and you get these benefits automatically.
- Scalar type and return type declarations
- New operators in PHP 7
- Anonymous classes
- Arrays as constants
- Catchable exceptions and errors
- Integer division with intdiv()
- Deprecations and deletions