The long-awaited version of PHP with ground breaking features and enhancements will finally hit the market on Nov 26 2020. It is currently in the pre-release phase where alpha, beta, and RC (Release Candidates) are being released one after the other as per their pre-defined release cycle. Recently, the PHP Beta 2 is released on 20th Aug, which also contains some impressive new developments.
Even though PHP 8.0 is still in the pre-release phase, the major improvements and upgrades are known and can be tested. But out of all, the JIT (Just In Time) compiler is the biggest improvement in PHP 8.0. JIT compiler helps to optimize and compile the running code at the runtime to execute it on CPU. Many believe that this feature will prove to be a benchmark in improving the performance of Magento 2. But does it really do anything? Will the features of PHP 8.0 improve the performance of Magento 2?
To answer that, we installed Magento 2 on PHP 8.0 and compared its performance with the Magento site running on PHP 7.3. And after we properly optimized both the site under the same circumstances, we were surprised to see the results, and you’ll also be astonished by the same. So, let’s get started. But let’s first see how you can install the latest PHP version. The following is our case scenarios, which might be different than yours and can affect the performance of the Magento store being tested.
Installation of PHP 8
The installation part of PHP 8.0 is quite easy and straightforward. Only one minor issue one can face while the installation is to install LibJPEG and LibPNG if you need to GD library to manipulate the image files on your PHP server. For testing purposes, we compiled, build, and installed PHP 8.0 with the following server conditions.
- Amazon EC2
- Nginx webserver
- MySQL 5.7 DBMS
- Amazon RDS
Along with all this, we used the latest Ubuntu version to carry out the installation process. This process is the same for other OSs with few being exceptions. So let’s get to the main part.
Dependencies are components such as packages, frameworks, libraries, and others your system needs to run project. And to compile PHP 8.0 we need a number of these dependencies. With the following code, you can install the necessary dependencies.
sudo apt-get update
sudo apt-get install git build-essential
libgccjit-6-dev libzip-dev autoconf re2c bison libxml2-dev -y
For some cases, these dependencies might not be enough for PHP 8 compilation so you need to install missing dependencies using –dev suffix/ or –lib prefix.
2. Cloning PHP Source Code from Git Repos
To get the latest PHP version, we need to clone the source code from Git repos with the following command.
git clone //github.com/php/php-src.git
The latest PHP version will be copied from the master branch but for our case, PHP 8 is installed.
3. Compiler Configuration
To configure the compiler, ./configure script file can’t be found and to generate one you need to force ./buildconf script. Once the configuration script is available, set up the compiler by employing -prefix flag. This will configure all the necessary PHP modules which are needed for Magento 2 installation.
We have used the server with 4 cores to make a build and with the following –j flag the process will become faster.
You will see the script which will show that the build is complete and asks you to run ‘make test.’ This will ensure the PHP compilation works or not.
5. Compile PHP Installation
To initiate the installation process use the following command.
sudo make install
To check this works or not use the following command
PHP 8.0.0-dev (cli) (built: Apr 5 2019 11:19:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
Once this is over enable the required extension such as OPcache for JIT. Once that completes, install Magento 2 on PHP 8. When we installed Magento 2 on PHP, we faced some problems and we are giving you the solutions for the same if you ever face them.
Magento 2 installation using PHP 8: Problems & Solutions
Despite Magento has its own standard installer, we faced quite a few issues and here’re their solutions as well.
Problem #1: Due to the incompatibility with M2 core, the implode functions in PHP 8 which accepts strict and documented parameters caused some challenges.
Solution: When we reshuffled the parameters manually, the problem was solved.
Problem #2: With PHP 8, M2 core can’t validate arguments absent with prefix “?”, which Magento 2 easily validated with PHP 7 and below.
Solution: To fix this issue, we added argument types prefixed with “?” in the core of M2.
Problem #3: M2 has some classes termed as match, which can trigger an error if it is used for class naming in PHP 8.
Solution: We renamed all the Magento 2 classes with match to fix the error.
Conclusion – PHP 8.0: Performance and Speed tests on Magento 2
Speed testing on simple code provided impressive results with and without turning JIT on. The load time of code reduced as much as twice when JIT was enabled compared to when it was disabled and reduced to almost 3X compared to load time obtained with PHP 7.3.
We know that PHP 8.0 is still under evaluation and development phase and JIT is fairly new right now. So, the speed and performance tests conducted on home, category, and product pages of M2 with PHP 8.0 were lagging behind compared to the its performance with PHP 7. But we can’t say that the final cut, which is scheduled to release in Nov 2020 will give the same results.
A team of professionals is still working on fixing the issues and bugs of PHP 8.0. And with GA, we can expect the better performance of Magento stores when upgraded to PHP 8.0. But for the time being PHP 8.0’s JIT is still far from perfect. However, it works completely fine and performs well with simple codes. We’ll keep our eye on the horizon and look for any changes in PHP 8.0 JIT as they happen and update you the earliest.
Till then, you can learn more about Magento’s latest version upgrade – Magento 2.4.0. Also, find out is it worth for you to upgrade to Magento 2.4 version. If you still haven’t, then migrate from Magento 1 to Magento 2 right now. And if you are unsure what to do, then you can always consult our experts for professional advice.