message

PHP 8 Available on Our Servers (What’s New + Game)

PHP 8 Available on Our Servers (What’s New + Game)

Table of Contents

We’re happy to announce that we have deployed the latest release candidate version of PHP 8 on all our servers. As always we are among the first companies to provide the new PHP on their hosting platform. PHP 8 is expected to facilitate developers to write cleaner code with better quality that gets executed faster. Since release candidates are not suitable for live sites, we invite you to try it out on a staging copy of your site or on projects that are not live yet. We’ll give away awesome PHP elephants to 10 of the early adopters who share their opinion about PHP 8 with us. 

What are the PHP 8 improvements and features

Faster code execution

The latest PHP version brings a lot of new things but the one we are obsessed with is JIT (just in time compiler). It is the first time that PHP version has a compiler – JIT – that caches a version of your already interpreted code and generates a machine code as an output (machine code is on with 0’s and 1’s only). The “just in time” compiler promises speed improvements for complex tasks and algorithms and opens new opportunities for the PHP language to broaden its reach and applications. 

Some of you may wonder how JIT relates to the Opcache, which brought significant performance gains to many websites? The main job of the Opcache is to cut the processes of tokenization, parsing, and compiling of Opcodes, which then get processed by the Zend engine. The role of JIT is to save on the execution of the Opcodes by the Zend engine, so it joins forces and intervenes to spare resources where the Opcache cannot help.

It’s worth mentioning a few downsides we have noticed so far:

  • Running PHP 8 with JIT might make it harder for you to troubleshoot code errors because it may be harder to locate which piece of your code in this interpreted version is actually at fault.
  • If you are running a WordPress site you may not be able to note significant performance improvements thanks to JIT. The WP developers are still working on making WP compatible with PHP 8 and are now calling for testers, meaning you won’t be really able to test PHP8 on your WP site right away. Also, because of the way WP interacts with MySQL, a lot of the waiting time does not come from the PHP compilation, but from the MySQL response time, which cannot be solved with the help of the JIT compiler.  

Code with higher quality 

One of the major differences that you will notice is that many of the warnings and notices that weren’t catchable are now exceptions or errors, which can be caught and logged. It is possible that due to this change, a lot of problems that remained hidden with the previous PHP versions will now surface. This is a great improvement, as it will allow developers to spot potential issues easier. However,  have in mind that it may be a good idea to set display_errors=Off if you decide to use PHP 8 on a live site to not show such errors to your site visitors.

Cleaner, shorter code

Some of the new elements, such as the nullsafe operator, greatly improve the readability of the code, making it shorter and neater.  Instead of nesting several “if’s” you can use the “null” operator to write all those in just 1 line of code. 

The “type” trend

For several versions now, PHP has been trying to define the arguments that each method could adopt and become more of a typed language. In this latest release, there is a feature called “union types” which allows you to define 2 value types for each function, which is a natural continuation of that trend. As the example below shows, the function can return an integer or a float: 

public function getNumber(): int|float {
return $this->number;
}

The list of new features keeps going and we suggest this article as a good reference point for PHP developers:

https://stitcher.io/blog/new-in-php-8
https://stitcher.io/blog/php-jit
https://wiki.php.net/rfc/nullsafe_operator

How to take advantage of PHP 8 on our platform?

All our clients can change the PHP version of their sites from their control panel – Site Tools > Dev section, or cPanel > PHP versions. With PHP8 still being a Release Candidate, we strongly advise that you do not enable it for your live sites, but run tests with it on our staging environment (staging is available for GrowBig, GoGeek and Cloud plans), or create copies of your sites in your accounts if you do not have the staging functionality. 

At the moment, we have deployed PHP 8 without the following modules: mcrypt, geoip, ioncube.

Tell us what you think and win a PHP elephant

We tried to give you the big picture on what the new PHP8 is all about. Now we would like to hear what you actually think about it, once you get the chance to try it out. What do you like and what do you dislike? How does it work on your website? Do you see any performance improvements? We are looking to explore how our more experienced users take advantage of this early release candidate before it becomes official.

To stimulate you to share your tests and opinions with us, we have styled and branded the original PHP elephants to celebrate this new release. We’ll give away 10 elephants to 10 random users who share their thoughts on PHP8 by November 26, 2020 in a comment under this post, or on Facebook or Twitter, tagging @SiteGround and using the hashtag #PHP8 in their post.

Related Articles

Back to top button