Speed up your shop with PHP 7 for Magento

in MagentoPerformance Tags: performancePHP

PHP 7.0 and PHP 7.1 are available on our Hypernode platform. This article explains how to switch to PHP 7.x and where to find more information about getting your Magento 1 shop working with PHP 7. Magento 2 is fully compatible with PHP 7.0; PHP 7.1 is officially supported from Magento version 2.2 onwards.

Available PHP versions on Hypernode

On Hypernode you can choose from a range of PHP versions:

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1

Why PHP 7?

PHP 7 definitely is a performance booster compared to PHP 5!

Also: since July 2016 PHP 5.5 is declared end-of-life. Which means the PHP team will no longer release (security) updates.

So in order to be safe, fast and future proof, it’s wise to update to PHP 7. If you have a Magento 2.2 shop, you could also choose to update to PHP 7.1.

Magento 1 compatibility

Magento 2 is fully compatible, but Magento 1 doesn’t support PHP 7 by default (Magento 1.9 supports PHP versions up to 5.5.x). Luckily Inchoo created a module which allows you to patch Magento 1 to work on PHP 7. It is very easy to install, follow the instructions below.

IonCube compatibility

We do support IonCube for PHP 7, but this extension is not enabled by default as IonCube is a massive performance killer.
Please contact our support team if you can’t work without it, so we can manually enable it.

We recommend anybody to contact the extension builder instead to provide a non-ioncube-encoded extension rather then activating IonCube. If this is not possible and you have no other choice, please drop us an email so we can enable it for you.

To check if you have IonCube encoded files, use the following command:

$ grep -lr 'if(!extension_loaded('"'"'ionCube Loader'"'"'))' --include='*.php' ~
/data/web/public/includes/src/Mico_Printsize_Model_Reader.php
/data/web/public/includes/src/Mico_Cmp_Model_Observer.php

Keep in mind that IonCube can cause in between 1 and 3 seconds additional load time of your webshop, effectively diminishing all performance optimization you have done on your webshop.

Download and install the Inchoo PHP 7 extention

To install the Inchoo PHP 7 extention, first check which Magento version you are using.
There are 2 versions of the Inchoo PHP 7 extension:

  • Magento 1.9.2.4 and below (including patch SUPEE-8788): Use the 1.9.2.4 branch.
  • Magento 1.9.3: Use the master branch.

To install, use modman. Use the following command, and replace $BRANCH with the branch you want to use, either “master” or “1.9.2.4”

modman clone https://github.com/Inchoo/Inchoo_PHP7.git -b $BRANCH

So, if you want to use the master branch, the command would be:

modman clone https://github.com/Inchoo/Inchoo_PHP7.git -b master

Don’t forget to flush your caches afterwards:

magerun cache:flush

If you want to automate the installation of plugins you can do this as well using composer. To do this, follow the steps in the Inchoo_PHP7 installation guide.

Test your shop in PHP 7

Switching PHP versions on Hypernode will remove the old version and install the new one. It is therefor not possible to test with 2 PHP versions on 1 Hypernode.

Before switching your PHP version we recommend you to test your shop to see if everything works as it should in the new PHP version. Testing your shop without having your customers notice anything can be done with Vagrant for Hypernode. Vagrant is a tool that gives you the opportunity to set up a virtual staging environment. How you can set up your Vagrant is explained in the article How to use Vagrant as a local staging environment. You can also temporarily order a development package to test PHP 7.

Testing PHP 7 compatibility

We added php7cc to detect incompatibilities in the PHP code. This is a very nifty tool to verify whether your code is PHP 7 ready.

For a full list of available functionality, use php7cc --help

Switch to PHP 7 in 5 easy steps

NOTE: Did you order a trial via Hypernode.com (by invitation only)? Be aware changing the PHP version of your Hypernode trial is not possible yet. Please contact us if you have an urgent reason to change your PHP version.

Byte.nl customers can easily switch the PHP version of a Hypernode via their Service Panel, but please thoroughly test a PHP change before implementing it on a live environment!

  1. Log on to your Service Panel
  2. Select your Hypernode by clicking the app name
  3. Go to tab ‘Hypernode’
  4. Click the PHP button
  5. Choose PHP 7

Migrating your Hypernode takes a few minutes.

PHP 7.1

We now support PHP 7.1 on our Hypernode platform. Since it is virtually a drop-in replacement it is definitely worth the effort. Performance-wise, you will gain a few percent. Not as spectacular as when upgrading from 5.6 to 7, but every bit helps. Next to performance there are also some new language features and a couple of new functions which might make it worth your while.

PHP 7.1 brings some changes that could impact your store. Please read the list of backward incompatible changes and deprecated features. From a Magento perspective, the most notable entry is the deprecation of ext/mcrypt, which is relied on heavily by Magento. Mcrypt is still available in PHP 7.1 but it will completely be replaced by PECL in PHP 7.2. The Magento Community Engineering team is currently working on making the Magento core PHP 7.2 proof.

PHP 7.1 and Magento 2 compatibility

Magento 2 is officially compatible with PHP 7.1 from version 2.2 and up. Earlier versions of Magento will likely run into compatibility issues. With earlier releases of Magento 2, issues have been reported with the mcrypt extension. Do you have a Magento 2.1.x shop and are you very keen on using PHP 7.1, please check this workaround published on
Cadence-Labs.

PHP 7.1 and Magento 1 compatibility

While not officially supported, it is definitely possible to run Magento 1 on PHP 7.1. To do so install the Inchoo_PHP7 module. But if you do go down that route, read this meditation by Ivan Čurdinjaković from Inchoo.

FAQ

I want to use PHP7 but I need IonCube for dealer4dealer to work

Although we nowadays do support IonCube, we don’t recommend using it, as it causes a massive performance decrease when enabling the IonCube extension.

There now is a newer open source version of the dealer4dealer extension called Xcore which does not need the IonCube plugin to work. Please contact Dealer4Dealer for more information.

How do I get Buckaroo or PostNL to work with PHP 7?

You might get errors using the Buckaroo plugin. Most of the times these errors can be resolved by clearing the wsdl cache.
You can find your PHP WSDL cache files in the /tmp directory:

ls /tmp/wsdl-*

To remove the wsdl cache, remove files starting with wsdl- from your `/tmp

rm /tmp/wsdl-*

If removing the cache files doesn’t work, it can be useful to temporary change the SOAP settings for PHP 7 while debugging. Put the following settings in your .user.ini:

soap.wsdl_cache = 0;
soap.wsdl_cache_enabled = 0;
soap.wsdl_cache_ttl = 0;

Disabling your wdsl cache can cause serious performance problems and should only be temporary to debug PHP 7 issues.

Is PHP 7 the default PHP version on Hypernode?

If you order a Magento 2 Hypernode, your PHP version will by default be set to PHP 7. If you choose a Magento 1 Hypernode or if we don’t know your preference, your Hypernode will by default run PHP 5.6.

Most shops still use a Magento 1 installation. Although Magento 2 is fully compatible with PHP 7, Magento 1.x versions are not. To avoid incompatibility issues with Magento 1, we automagically select PHP 5.6. You can change the PHP version for your Hypernode from our service panel

Does Varnish work with PHP 7?

The currents stable release of the Turpentine varnish extension is compatible with PHP 7.

For Magento 2 shops there is no Turpentine module, so using your own VCL is the only way to use Varnish. Read more about configuring your own VCL.

Troubleshooting

  • There are some known issues when using the backend with Magento 1.9.2.4 and PHP version 7.0.6. To avoid these issues, install the dev-master version with composer.
  • Don’t use persistent Redis connections with PHP 7. Make sure the <persistent> setting is empty in your Redis XML files.

2