Learn the Setup and Performance of PHP7



PHP 7 is the advance version of PHP, released on 3rd Dec 2015. In this chapter, we will discuss about the performance and added features of this advance level and also, we will see the step by step guide to set up PHP 7.
Before we can start tutorial on PHP 7, we assume that you are well versed with all the previous versions oh PHP.

Introduction to PHP 7
PHP 7 can be considered as a renaissance in the field of development of web applications, mobile applications and cloud computing. It is one the major and important release with added features from other PHP 5.x versions. These added features are:

  • Performance: PHP 7 is two times faster than PHP 5 as it has PHPNG (PHP Next Generation) branch code merged with the master code.
  • Memory Consumption: PHP 7 consumes less resources and memory when the program code is well optimized. It uses new Zend Engine 3.0 which reduces up to 50% of memory consumption as compared to PHP 5.x versions.
  • Declaration of Scalar and return type: With the PHP 7 release, we can enforce the use of parameters and return types in PHP programming.
  • 64-bit architecture machines support: PHP 7 supports 64-bit architecture machines. Thus not limited to 32-bit architecture machines.
  • Improvement in the Exception hierarchy: With the improvement of exception handling in PHP 7, many of the fatal errors are now converted to Exceptions which has increased the overall range of exception coverage.
  • Random number generator API: PHP 7 has added a secured random number generator API.
  • Deprecated SAPIs and extensions: PHP 7 release has removed various unsupported SAPIs and extensions which were old and not in use.
  • Null coalescing operator (??): PHP 7 release has added new null coalescing operator.
  • Anonymous Classes: PHP 7 release has added support for anonymous Classes.
  • Zero cost asserts: PHP 7 release has added support for zero cost asserts.

Performance comparison PHP 5.x vs PHP 7.0 for utilities

  • Magneto 1.9 running over PHP 5.x vs PHP 7.0 has the performance ratio of 4:7 for requests per seconds.
  • Drupal 7 running over PHP 5.x vs PHP 7.0 has the performance ratio of 1:2 for requests per seconds. It is almost 2 times faster than before.
  • WordPress 3.6 running over PHP 5.x vs PHP 7.0 has the performance ratio of 99:204 (~1:2) for requests per seconds. It is almost 2 times faster than before.

PHP 7 Environment Setup
To run PHP 7 web pages, we need four components.

  1. Apache web server.
  2. MySQL Database.
  3. PHP 7 Parser.
  4. Eclipse IDE.

Below are the step by step instructions to set these up. In this tutorial, we are installing XAMPP setup which has integrated Apache web server, MySQL database and PHP 7 parser along with Eclipse MARS version.

XAMPP Installation steps
Step 1: Open any web browser and enter the URL (https://www.apachefriends.org/download.html). The web page will display options to download installer of various PHP versions for windows OS. Choose the PHP version as 7.0.6/PHP 7.0.6 which is 118 MB in size for 32-bit hardware architecture.
Step 2: Upon clicking the download link, a file ‘xampp-win32-7.0.6-0-VC14-installer.exe’ will be downloaded. Double click on this installer, it will display an XAMP Setup Wizard as shown below.
Step 3: Click on the ‘Next’ button to select all the required components to be installed. Here, we need Apache web server, MySQL database and PHP 7 parser. Select their checkboxes and click on the Next button.
Step 4: System will ask to select an installation folder, we are using ‘C: \xampp’ as the installation folder which will have all the required components. Click on the Next button to proceed.
Step 5: Click on the next button again on this screen as displayed.
Step 6: At this step, XAMPP installer will start unpacking all the required components files and start installing these components at the chosen directory as shown below.
Step 7: Once installation is completed, click on the Finish button to complete XAMPP setup wizard. At this point, all the required components are ready to use.
Step 8: XAMPP comes with control panel, which can be opened after double click on ‘C: \xampp\ xampp-control.exe’ file as shown below. Using this panel, we can start, stop, configure and see logs of the components such as Apache, MySQL, etc. This panel also displays the process ids as well as the port number where Apache and MySQL are operating.
Good news is that, the xampp setup for Apache web server and PHP 7 parser are pre-set in ‘C: \xampp\apache\conf\httpd.conf’ and ‘C: \xampp\php\php.ini’ files respectively.

Configuration in php.ini file for PHP Parser
This file has the information that configures PHP to work with the current environment setup. Following are the important directives for php.inf file.

  • extension_dir: This directive has the path of the directory in which the loadable extensions (modules) reside. In the current set up it is extension_dir=”C:\xampp\php\ext”.
  • extension: It enables the required extensions e.g. Xyz.dll. This directive directs PHP to load only enabled extensions at start up from the extension_dir.
  • error_log: This specifies the path (absolute or relative) where PHP error logs will be generated. In the current set up it is error_log=”C:\xampp\php\logs\php_error_log”.

Likewise, there are other directives such as cgi.force_redirect, cgi.fix_pathinfo, fastcgi.impersonate, fastcgi.logging, etc. that are present in php.ini file.

Configuration in httpd.conf file for Apache Web Server
This file has the following important directives for the web server.

  • DocumentRoot: This directive tells Apache web server the path where web pages (PHP, HTMP, etc.) are located. In the current set up they are located at DocumentRoot “C: /xampp/htdocs”.
  • ServerRoot: This directive tells about the web server root path. In the current set up it is ServerRoot “C: /xampp/apache”.

Eclipse Installation steps
Step 1: Enter the URL (http://www.eclipse.org/downloads/packages/release/Mars/2) in the web browser and click on the download link to download eclipse. We are using Eclipse MARS version here.
Step 2: Unzip the eclipse package and provide the system installed JRE 8 (Java Runtime Path) for javaw.exe file for eclipse to work. The file eclipse.ini present in eclipse directory has the javaw.exe path which helps in starting the eclipse.
Step 3: When eclipse starts, it will ask you to choose a workspace. Select an appropriate location such as “C:\PHP_Workpace” and click OK to complete this step.
Step 4: Open the PHP perspective for PHP projects in eclipse. If PHP perspective is not present then navigate through the links on eclipse as Help -> Install New Software. Work with the URL (Mars – to add PHP software into eclipse as shown below.
Step 5: At this point, the eclipse is integrated to PHP and ready to use.

In this chapter, we first discussed about the advanced PHP version which has a better performance than previous PHP 5.x versions and has added new valuables features. Then, we covered the installation of the key components such as web server, PHP 7 parser and MySQL database along with Eclipse as IDE which are required to run web pages. In the upcoming chapters, we will develop PHP programs for new PHP 7 features and execute them using these key components.


Please enter your comment!
Please enter your name here