WordPress with PHP 7 – Why to Upgrade Your Serveradmin
PHP 7 has launched in Dec 2015 and even after a full year from initial release there are websites that are still running under older versions. PHP 7 is a major change for the better. It is a much improved version of one of the most used scripting languages and the core foundation of WordPress. In this article I am going to cover why is so important to upgrade to a hosting that properly provides support for it and why it would benefit your site.
Benefits of PHP 7 for WordPress
PHP 7 is on version 7.1.4 now but the core essentials still remains, this are the most important aspects that changed from PHP 5.6 and older versions to 7
- New Zend Engine now called PHP Next Generation (NG)
- Important reduction in the memory usage
- Abstract Syntax Tree
- Consistent 64bit support
- A good number of fatal errors now converts into exceptions
- Better and more secured number generator
- Anonymous clases
- Compatibility with OpenSSL 1.0.2e onwards.
So, still don’t know what all that mumbo jumbo actually means?, let me explain all of that in detail.
Wait – What Happened to 6?!?! The development cycle for PHP 6 did exist but the former attempt never made it to the public (don’t worry – you didn’t somehow miss it). To prevent confusion it was decided 6 was going to be skipped. This served the purpose to further improve development of PHP 7 and launch a more polished version with much more features and benefits.
The New Zend Engine
For those of you who doesn’t know, Zend is not new to PHP because it was there since 1999. Zend is the execution engine that does the actual interpretation of PHP language. It was written in C and had several upgrades through time. The version that PHP 5.x uses is called Zend Engine II and adds the extensible object model and performance enhancements compared to older versions but the new Zend Engine in PHP7, now called Next Generation is the core for the actual speed increase of PHP7.
Whenever you hear the phrase twice the speed and significant reduction of memory consumption of PHP7 you’ll know it’s actually Zend Next Generation improvements.
Next Generation achieves this by changing it’s behavior of operating with pointers (such us previous Zend Engine II) to operation with structures. This change reduces memory consumption, garbage collection and overall performance. A more in-depth explanation recommended only to coding warriors is available on the PHP wiki.
PHP 7 Is Way Faster
The changes in Next Generation Zend Engine are the main responsible for the increase in speed , by reducing memory consumption they also reduced the time the scripting language takes to process the information and the result is that PHP 7 will need less servers to provide the same content. This is awesome for you because who doesn’t want to speed up WordPress.
This is a graph directly taken from the PHP PDF:
The number of request per second is a good measure of performance because it basically tells you how much users will be able to see your site at any given time based on your server and software. The more requests the server can serve the faster your website will be. PHP 7 is able to duplicate the performance of PHP 5.6 and directly compete with HHVM, another script language interpreter made by Facebook.
Why is faster?. Because it uses less CPU time to process each request, hence, it can double the amount of requests that can serve at any given time.
Improved Error Handling and 64bit Support
One of the most criticized things in PHP was the handling of errors. Why you may ask?, because previous to PHP7 a fatal error was something almost impossible to handle properly since it would not invoke any error handler and would halt script execution.
The improved PHP 7 error handling uses throwable exceptions this allow developers a much better handling mechanism to deal with errors that was previously unavailable. By creating exceptions developers are able to get much better information about the actual error and are able handle it properly.
Tip: it’s much easier to code now and less of a headache.
On the other hand the consistent 64-bit support means that PHP7 now allows 64bit integers and is supported in other platforms, like Microsoft Windows running natively at 64-bit.
PHP 7 Supports Anonymous Classes
There is a practice in all the major object oriented languages to use anonymous clases. Java and C# have abundance of those. Anonymous classes are not only very useful but properly coded can speed up code execution, adding anonymous classes was necessary for PHP7 to catch up with all the major object oriented languages.
Deprecated PHP Functions
There was major house keeping in PHP7 with deprecated functions. A deprecated function for those who don’t know is a part of code that is considered too old or unusable and calls for deprecation. When a function is deprecated in PHP it no longer works.
The developers of PHP7 carefully considered a lot of functions that were no longer being used. It’s important to know that a deprecated function can and will potentially break your code. When you hear about compatibility issues with upgrading your WordPress to PHP7 this is the exact point where your website can brake.
The deprecated functions in PHP 7 is the single most important point to consider when upgrading your website to a hosting that provides PHP 7
Older plugins and themes calling those deprecated functions can and will stop functioning if they are running under PHP7. That’s why you absolutely must upgrade all your plugins & theme prior to switching to a hosting that supports PHP7.
The removal of all that deprecated code is in part responsible for the performance of PHP7 which now runs in a far cleaner environment than PHP 5.x
What All This Means
PHP7 is faster and more lightweight, runs with less memory usage, executes twice the amount of code at any given time than PHP 5.x and it handle errors in a much cleaner way. This all translates into a faster website, better coding and a much better user experience.
If you care about performance on your site your first order of the day should be to upgrade all your plugins & theme and switch to a hosting that provides PHP7. And you’re in luck – most popular hosting companies offer PHP 7 for all of their plans (or they offer the upgrade). Here are a few PHP 7 compatible hosting companies we recommend:
Of course there are other factors that contribute to even more performance such as using nginx and hosting services that support some kind of webserver cache but we will discuss all of those topics in a later article. For now, if you have anything to add or any questions let us know in the comments below!