How PHP 7 affects websites?
Depending on what you use on your site, either a custom content management system, a hard coded website in PHP or one of the popular CMS available on the internet such as WordPress, Joomla, Drupal and Magento and so on, PHP 7 can affect your website from various points. And one of the most important ones - your site will be twice as fast. If you want to more know how your site speed affects your business, check our infographic here.
Summary, PHP 7 will affect websites because it is a standalone multi-threading web server, asynchronous programming language and it has abstract syntax tree and huge performance improvements.
Now let's get a bit more technical.
You should know that for WordPress 3.6 there are more than 200 PHP 7 requests per second while for WordPress 4.1 there are about 375 requests. For Drupal 7 are more than 317 PHP 7 requests per second and for Drupal 8 Beta are 55 PHP 7 requests.
So your websites will work much better because PHP fixed a lot of bugs related performance issues and it is twice as fast as previous versions. Also, things will run easier and smooth because of all PHP 7 new features presented above.
Regarding WordPress websites, PHP 7 can break your site if the WordPress developer does not work to make a new stable version of WordPress because of incompatible changes and updates between new PHP and old WordPress versions. Also, third party plugins, scripts, and themes can now have additional bugs until they are updated with PHP 7 WordPress team.
already started to fix and prevent bugs related to PHP 7 and also some third party developers, but most of them are not rushing to do the proper changes.
If you want to migrate from PHP 5 to PHP 7, you should look at notifications and especially warnings, exceptions and errors. Most of the hosting providers will offer you a notification so you should know about their PHP migration. Also, do not forget to back up your WordPress site even if you are sure the migration will be successful. Another good idea is to update themes, translations, plugins and even the core before you migrate.
With Drupal sites, it seems that Drupal works on PHP 7 but only on Windows Server IIS 8.5 with MySQL database and with Zend Opcache turned on for now.
The PHP 7 has 490 requests per second while PHP 5.6.6 has 310 requests per second. With page caching enabled PHP 7.0 gets 1800 requests per second while PHP 5.6.6 1550 requests per second. It seems that PHP7 is benefiting more on dynamic websites. Neither Drupal 7 nor Drupal 8 do not support officially PHP 7. However, it seems that Drupal 8.0.1 using HHVM 3.10.1 is faster than using PHP 7. This was tested using a benchmark with the following versions: Ubuntu 14.04, MySQL 5.5.46 and Nginx 1.4.6.
For Joomla, the 3.5 version supports PHP 7 while older versions do not support it. Joomla 3.5 comes with a new release 3.5.1 fixing some bugs. It also has features such as UX improvements, editor for images with drag and drop and flipping and new emojis and notifications, anonymised data, insertion of modules into articles, updated emails and system info export.
On Magento, PHP 7 runs three times more transactions on the same hardware with execution time more than twice as fast compared to other PHP versions and with 30% lower memory consumption. So at the homepage, at Magento 1.9, PHP 7 gets 69 requests on the second while at the catalog page 17 requests on second.
If you have a website built on the framework Laravel, you will get 485 requests per second while for Zend Framework you will get a little more, almost 500 requests per second. Zend provides you with testing environment, certified PHP 7 stack, tested extensions and productivity tool. Symfony also supports PHP 7 being fully compatible with it. On SugarCRM, PHP 7 gets 270 requests per second.
Compared with other dynamic languages PHP 7 is faster than Ruby 2.1, Python 2.7.8 and Perl 5.18.4.
As a conclusion, your website will be much faster, but you need to have your hosting and your website upgraded else if it is not compatible with PHP 7, you will damage your project having multiple bugs. The top UK hosting providers in our list support PHP 7 and you have to chnage the version from your hosting control panel.
A bit about PHP
PHP is a programming language used especially by web developers to create websites and online applications. It is functional, procedural, imperative, reflective and object-oriented. It was created 21 years ago on 8 June 1995 by Rasmus Lerdorf, and it is updated by Zend Technologies.
As implementation languages, PHP uses C and C++. There are multiple file extensions well known that contains PHP code such as .php, .php3, .phtml, .php4, .phps and .php5. PHP development and updates were influenced by Perl, C, C++, Java and Tcl.
PHP 7 comes with a lot of features
Scalar type declaration which comes in coercive or strict types. Also, you can use parameters such as integers, strings, Booleans and floating point numbers. Return type declarations are supported now and are similar to argument type declarations.
Null coalescing operator is added, and it is returning its first operand if it exists or NULL if it not exists, else the second operand.
Spaceship operator is also supported, and usually, it is used to compare two expressions.
Constant arrays can be defined with define() not like in PHP 5.6 where they where they were defined with cost.
Anonymous classes are available through new class.
Unicode codepoint escape syntax is also supported in PHP 7
Closure::call() is a new and performant shorthand way to bind temporarily an object scope to closure. You can use this also to invoke it.
Filtered unserialize() is a new feature which allows you to offer better security while unserializing objects on suspicious data.
IntlChar is a new class which exposes additional ICU functionality by defining some static methods together with constants that are used to modify Unicode characters.
Expectations are used to allow for zero-cost assertions in production code improving this new API while the old one is still maintained but not recommended.
Group use declarations are used for classes, functions and constants when you want to import them from the same namespace.
Generator return expressions help to improve the PHP 5.5. Generator functionality.
Generator delegation can now delegate other generators.
Integer division with intdiv() is now possible.
Session options are available through session_start() which accepts an array of options.
Preg_replace_callback_array() is a new function which enables code to be written more cleanly, something much better than other PHP versions before PHP 7.
CSPRNG functions are available also, and they contain two functions added to generate cryptographically secure integers and strings.
List() now can always unpack objects implementing ArrayAccess while previously this was not possible.
Throwables are also changed in this version, so errors are no longer raised the way they used to be. They behave almost the same as exceptions, both being inherit from the Throwable interface.
Level support for the dirname() function has increased so it has a second argument now that shows how many levels you were going up the root. Uniform variable syntax is a new standard added in PHPH 7 which changes the access to array keys, methods, and properties.
Performance is twice as better than PHP 5.6, and the speed of PHP 7 is almost twice as fast as the old version.
Abstract Syntax Tree also named AST is added intermediating the representation of the code during compilation.
64-Bit Windows Systems support.
PHP 7 Tools
In order to test and check your PHP 7 code but also to convert an old PHP code such as PHP 5 you can use some PHP 7 tools available on the internet such as:
- Php7cc, which checks the compatibility between your code base and PHP 7.
- Php7ize fixes your code adding PHP 7 features.
- PHP7MAR is a migration assistant report helping you to find errors, warnings and other notifications comparing your code with PHP 7.
- Exakat is a useful analyzer which turns PHP in analytics. This tool is also used by phpMyAdmin.
- PhpStorm comes with PHP 7 mode.
- Phan is a static analyzer.
- Vagrant is created by Rasmus Lerdorf, and it can test multiple versions of PHP.
- Tuli is another analyzer.
- Travic Cl is used for projects in PHP 7.
Avoid some PHP 7 practices
PHP 7 is great, but it is still new and not fully compatible with all content management systems and frameworks. Also, being so new it is not tested by a lot of people. You should avoid a couple of practices because else you will get a headache regarding your websites and your web applications. So avoid the following practices on PHP 7:
- You should not use mysql_ functions because PHP 7 will remove them from the core which means that you will need to use mysqli_ functions instead.
- You also should not write a lot of code. This is a bad practice for every type of PHP, but also for other programming languages. Only because PHP 7 is faster that does not mean
- that you can make your website loading speed lower than usual PHP 7 websites by writing a lot of unusual code.
- You should not use PHP close tags at the end of the file. For example, WordPress files are not using these close tags and also Zend Framework files. It is not necessary, and it can offer you some bugs.
- You should not use reference if you do not need so you can become a good programmer.
- A good, bad practice even for another programming language is to use queries in a loop. In this case, your query will never end.
- Stop using asterisk in SQL queries and start specifying the exact column you are searching.
- Never trust what users fill in the forms. You should always filter, validate, check and search for the proper data.