PHP 7 Tutorial
Introduction
PHP 7 is a major release of PHP in 11 years. PHP 6 was never released but most of the features that were meant for PHP 6 were release under higher versions of 5.x. These tutorials will introduce you to PHP 7. We will focus on new features and improvements that have been released. We will also look at the deprecated and deleted features from the old versions.Topics to be covered
We will cover the following topics;- Tutorial pre-requisites
- Downloading and installing PHP 7
- PHP 7 Performance
- PHP Earlier Versions Performance
- HipHop Virtual Machine
- PHP 7 Performance Vs (HHVM 3.7 & PHP 5.6)
- MVC Frameworks that are compatible with PHP 7
Tutorial Pre-requisites
For you to successfully complete this tutorial, you will need to know/have the following pre-requisites- This tutorial assumes that you know the basics of PHP.
- You have an IDE such as NetBeans or a text editor i.e. Sublime Text, Brackets etc.
Downloading and installing PHP 7
In my experience, the simplest way to install PHP and all the other associated programs i.e. apache web server, MySQL etc., is via XAMPP. XAMPP is cross platform so you can install it on Windows, Mac OS, and Linux based operating systems.You can download the appropriate installer for your operating system from the official website https://www.apachefriends.org/index.html. Make sure you download the installer that comes with PHP 7. For these tutorial series, I am using Windows 10 and XAMPP installed to drive C.
Installing XAMPP is just like installing any other program at least for windows. I am assuming the same for other operating systems such as Mac OS, and Linux distributions. Use the comments section below to ask if you have any questions.
By default, Apache web server that comes with XAMPP runs on port 80. Assuming you didn’t change anything, load the following URL in your favorite web browser.
http://localhost/dashboard/phpinfo.php
The above URL will give you system information related to PHP. The PHP version displayed should be 7.x If you get a different version then you did not download the correct version.
PHP 7 Performance
PHP Earlier Versions Performance
One of the things that people used to complain about PHP’s earlier versions was performance. If you have a local web application or a website/blog that doesn’t get a lot of requests, then you are probably fine with PHP earlier versions’ performance. But if you have to process a lot of requests then you will notice the performance issues.HipHop Virtual Machine
Facebook uses PHP for some of its site functionality. As a workaround to the performance issues, Facebook developed HipHop Virtual Machine (HHVM). HHVM uses Just in Time (JIT) compiler to improve the web experience. HHVM is open source and you can find more information about it from the official website http://hhvm.com/. HHVM is a great alternative to performance and it works but if you can get the same or similar performance gains from out of the box then I say consider switching to PHP 7. In fact, this is one of the major reasons why you should start using PHP 7.PHP 7 Performance Vs (HHVM 3.7 & PHP 5.6)
In a nutshell, PHP 7 has better optimization and has lower memory usage. It has nearly doubled the speed. Theoretically, this means if you your current lower versions processes 100 requests per second, you can now handle 200 requests per second by just upgrading to PHP 7.Zend did some benchmark tests on the performance of the PHP 7, PHP 5.6, and HHVM 3.7. The results of these tests are published on their website http://www.zend.com/en/resources/php7_infographic.
The table below summarizes the benchmark results
Based on the benchmark results provided by Zend, PHP 7 has better performance compared to HHVM 3.7 & PHP 5.6. The above results are only from one source (Zend). It is possible to find results that may show HHVM to out performs PHP 7. The important thing to take from here is PHP 7 has superior performance compared to PHP 5.6. If you have HHVM and would like to test PHP 7 then you can give it a try.
MVC Frameworks that are compatible with PHP 7
It is safe to assume that most modern MVC frameworks’ latest releases support PHP 7. But you will need to verify before you upgrade to PHP 7. Some of the top MVC frameworks that are compatible with PHP 7 include- Laravel 5.x
- Zend Framework
- Symfony
- Phalcon
Summary
PHP 7 is a major PHP release that significantly improves the performance and comes with lots of cool features that make PHP even more fun.What’s Next?
The next tutorial will look at PHP 7 Scalar Type Declarations. In a nutshell, you can now have the option specify the variable data type when declaring variables.If you found this tutorial useful, support us by using the social media buttons to like and share the tutorial. If you didn’t find it useful, please use the comments section below to let us know how we can do better next time.