Hello,

today we want to talk a little bit about PHP 7.4 and why clients should upgrade to PHP 8.x as soon as possible. Many companies are still running on outdated PHP versions, even PHP 5.6 or lower. To people who are unaware of what PHP even is, have the PHP officials explanation for it: PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used and generally intended open source scripting language that is specifically suited for web programming and can be embedded in HTML.

So, we now learned that PHP is the fuel that drives your web application. Most websites are running on a PHP interpreter which eventually are serving the rendered content back to the clients browser. Now, every language evolves, just like English evolved over the course of years. In PHP, its not much different. So, what changes? Usually, a programming language becomes more versatile, more stable and adds functionality for the developers to ensure better, cleaner code.

Now why is it important to upgrade to PHP 8.x? One of the major adaptions of PHP was the "Just in Time" (= JIT) compiler, that will render your applications code on the fly, thus executing it faster. This makes sense for long running processes, but not so much for applications that are just being rendered and served. Lets have a look at the PHP benchmarks for PHP 7.4 and the newer PHP 8.x:

PHP7 and PHP8 Benchmarks

You can see that the execution time reduces with higher PHP-Versions. From 7.3 to 7.4, the increase of speed was rather low, but its nearly 25% faster between PHP 8.0 and PHP 7.4. Whilst this should be a good motivation to keep your PHP version up to date, that is not merely everything you should take into account when discussing an upgrade internally.

There is even a bit more to consider here, lets have a look at the benchmarks of this website.

One of the major flaws with outdated frameworks is that nowadays 0-day exploits can see the daylight, and often they are being used to target high-value targets, like eCommerce websites. Whilst any grown company usually uses caching to improve their site performance (more or less...), the benefit of the performance of rendering the pages will not be so much noticeable. However, if the shop gets hacked and is offline due to ransom, this becomes pretty much noticeable, not just to the company but also to the customers. The potential damage for a hacked company can be immense. If there is a data loss it can be even worse. 

So, why should I upgrade now exactly?


Ask yourself: do I maintain a website that makes revenue, or am I managing a blog? If you run a blog, upgrade to PHP 8 for the performance. Most likely, the financial aspect will not be so high plus there is a good chance that you have not a few millions lines of code inside your code repository. In this case often, your infrastructure is not gigantic just as well. Ever heard of Redis?

However, if you run an eCommerce platform and you serve multiple hundreds of thousands customers per day, you should consider upgrading to PHP8 for security purposes, not for performance KPIs. But there is one big point that you might be unaware of: if you're already running PHP 7.4, the upgrade will be relatively easy and feasible for you. Its different tho if you run still on PHP 5.6.

If you feel like you're lost and you need assistance for that, you can always reach out to us and we'll be happy to support you with the upgrade. We've quite some experience with it, too.

But here comes the twist. If you have a grown, maybe even legacy-like, system, upgrading can be not straight forward. 

Here is a checklist for you to make sure you don't miss a spot when you want to upgrade:
  • make your application locally available -> create yourself a Docker environment where you can very easily upgrade to different PHP versions
  • once you have it, upgrade your PHP version of Docker to the highest possible PHP version that your hoster offers you
  • Now, run your Unit Tests or Integration tests. If you don't have them, browse trough your application and check the logs for any exceptions
    • If you don't find anything problematic and you can use your application locally just fine, great! You can most likely just upgrade the PHP version
  • If you find errors caused by PHP, check them one by one. Step trough the code with a debugger like xDebug, identify the deprecated function calls and replace them with a polyfill function or the proper replacement
  • once you have a basic functionality again, upgrade your composer packages. Now this can be a bit tricky:
    • check if your composer.json is set to a specific PHP version
    • upgrade to higher carret versions (many packages are set to use a specific range of versions, often declared as "^6" or similar. Check their individual Github Pages if they offer newer releases.
    • Symfony for example offers a detailled guideline how to upgrade: https://symfonycasts.com/screencast/symfony6-upgrade/php8
  • Once this is done, you should be able to remove your vendor and composer.lock file and reinstanciate your composer package with composer install

Don't forget to upgrade your pipelines just as well. 

Once you're done with everything, its time for you to upgrade your hosters PHP version and then you'll probably have to redeploy. 

Please never forget to make usage of Githubs version system to be able to roll back any changes you're making. Nothing hurts especially businesses more than downtimes. The faster you can rollback, the better it will be for you and your brand. 

As a last note its worth saying that if you're concerned for performance, the upgrade to PHP 8.x will not just allow you to use the JIT feature, but that you should also consider to enable OPCache functionality. By doing so, PHP will not be required to parse each script for each request. We will write an article about it soon, so make sure to stay tuned.