What a year 2015 has proven to be for PHP. Drupal 8, Magento 2, Symfony 3 and the icing on top of the cake – PHP 7!
It’s hard not to be excited about PHP 7. It’s so much more than just another major PHP release, and the long buildup and the buzz surrounding this release are far from being unjustified. PHP 7 promises to be a real game changer for the PHP world and the web as a whole.
Want to know what the fuss is all about and how to safely join the revolution? Read on!
Performance, performance, performance
We live in a world of instant gratification and constant changes. We expect and rely on our apps to run with the speed of light and web technologies are taking brave and innovative steps to comply with this insatiable need.
Packing the new Zend Engine 3.0.0, drastically improved performance and better memory consumption – PHP 7 is PHP’s answer to this ever-growing demand for speed.
Don’t take my word for it. Just in case you missed the party, take a look at some graphs first shared during Andi’s keynote at ZendCon in October:
The ability to run real world apps up to two times faster than 5.6 (and even more) is the main reason behind the buzz and why PHP 7 is considered by many as the most important development in PHP since 2004.
Naturally, in addition to the undisputed coolness factor, increased performance translates directly into very tangible benefits. Most notably, better end user experience thanks to faster response times, and reduced infrastructure costs thanks to being able to serve more concurrent users with the same (or even less) hardware.
PHP 7 also includes some language changes and additional new features, such as new operators – the spaceship operator and the null coalesce operator, scalar type hints, return type hints, to name a few.
You can read more about these new features here.
Starting the great migration
So, how to begin your move towards PHP 7?
Your first step is to understand more about how to migrate your PHP 5 code. The good news is that backward incompatibility issues have been minimized. In fact, there were literally no compatibility issues introduced as a result of the deep brain surgery the Zend Engine – PHP’s ‘kernel’ – underwent to achieve PHP 7’s amazing performance.
However, as a part of the planning for PHP 7.0, the PHP team has made several informed decisions that introduced certain compatibility breakages – ones that were deemed minor enough and sensible enough to be included in a new major version. Indeed, most involve the removal of deprecated items that have been out of the game for quite a while now anyway. Check out php.net for information on these incompatibility issues and deprecated features, as well as a list of the new features you need to know about.
In addition, there are tools out there that will help you with the migration process itself, one being Zend Studio. The latest version of Zend Studio includes a new migration tool called PHP 7 Express which helps you get a precise picture of what needs to be fixed in your code to be able to run it smoothly on PHP 7.
PHP 7 Express scans your code for compatibility issues – such as new reserved words and deprecated usage patterns – and then displays a list of all the issues it identified. You can then read what the issue is and open the exact corresponding file and line in your project.
Zend Studio also offers a quick-fix solution for the change in dereferencing syntax that was introduced in PHP 7, allowing easy conversion of the code to the new unified form, after which source code will retain the PHP 5.x meaning by adding braces to the problematic expression (allowing the code to continue working as expected under both PHP 5 and PHP 7).
Setting up PHP 7
Once you’ve started the migration process, you need to start thinking about the PHP 7 stack you’re going to install to test your apps on.
The recently announced Zend Server PHP 7 tech preview provides you with a safe and easy way to start.
Zend Server is a professional, certified and secure PHP stack, with advanced tools for developing, debugging, deploying and monitoring PHP apps.
The Zend Server PHP 7 tech preview is the most comprehensive PHP 7 stack currently out there and it includes the largest amount of tested extensions. Managing and configuring this PHP 7 stack is made easy by the Zend Server UI.
Not only that, you’ll also be able to use Z-Ray, Zend’s advanced development tool, on your PHP 7 code.
Installation is made easy using an installer script that does all the hard work for you. All you have to do is run the script, and all the required prerequisites and packages are verified and installed.
Important! The tech preview is currently only supported on Linux 64-bit (Debian 7/8, Ubuntu 14.04, CentOS 6/7) with more operating systems to be supported soon!
Sign me up!
How do you get started?
First, visit Zend.com and download the Zend Server PHP 7 tech preview installer script.
Once you’ve extracted the downloaded package (ZendServer-9.0.0-TechPreview-RepositoryInstaller-linux.tar.gz), simply run this command:
./install_zs.sh 7.0 --automatic
After installing, a completion notification will appear, with a notice that the server has started.
To access the Zend Server UI, open your browser at: https://<Server_IP>:10082/ZendServer (secure), or http://<Server_IP>:10081/ZendServer.
Complete the launching wizard to access the UI, and then go to the PHP | phpinfo() page to check out info on your server and PHP, or go to PHP | Extensions to configure and manage your stack.
Deploying your code
To run your app on Zend Server and PHP 7, simply place your code in the web server’s root directory (/var/www or /var/www/html).
Then, open your browser and enter the following URL:
PHP 7 will run your app, and if there were no serious PHP errors, you will see your app displayed in your browser and Z-Ray at the bottom of your page. You can then start using Z-Ray, Zend’s advanced development tool, to identify issues and fix your code.
Or – you can deploy any of the sample apps Zend Server comes bundled with using the Getting Started page. Select an app and complete the short deployment wizard.
Here are some additional resources you can use to read up about PHP 7. Enjoy!
- What to Expect from PHP 7 by Lorna Mitchell
- High Performance PHP 7 by David Stewart
- PHP 7: The Big 5+1 by Cal Evans
- What to Expect When You’re Expecting: PHP 7, Parts 1 & 2 by Davey Shafik
Viva la PHP 7 Revolución!