On November 26th, 2020, PHP 8 was released to the world. Two years later, PHP’s latest version 8.3 offers new features and improvements promising to enhance the security and performance of our WordPress sites.
WordPress Core is compatible with PHP 8 since its 5.6 release. But should I upgrade right away?
Let’s analyze the main changes and how to get the best PHP 8.3 WordPress compatibility checker.
Table of Contents
- What Performance Changes Are Coming With PHP 8?
- Is WordPress Compatible With PHP 8?
- Is My WordPress Setup Compatible With PHP 8?
- Our Recommendation:
What Performance Changes Are Coming With PHP 8?
The most exciting performance feature coming to PHP 8 is JIT, short for “Just In Time” compilation. PHP is an interpreted language, which means it gets translated into machine code as it runs. JIT keeps track of frequently used code and attempts to optimize the machine code translation to reuse it. As a result, it can improve the performance of specific functionalities.
The RFC proposal describes JIT as follows:
“PHP JIT is implemented as an almost independent part of OPcache. It may be enabled/disabled at PHP compile-time and run-time. When enabled, the native code of PHP files is stored in an additional region of the OPcache shared memory, and op_array→opcodes[].handler(s) keep pointers to the entry points of JIT-ed code.”
https://wiki.php.net/rfc/jit
WordPress Performance with PHP 8 JIT
The PHP8 compilation tests show that JIT would make CPU-intensive workloads run significantly faster.
The JIT Compilation approach in PHP 8 means significantly better performance for numerical calculations and slightly better performance for typical PHP web applications.
Tested environment | Performance improvement |
---|---|
PHP Benchmark Suite | 3x Faster |
WordPress | 3-5% Faster |
Framework-based Apps | No Difference |
JIT works best with CPU-intensive processing like repeated numerical calculations or Big Data analysis. Given this, WordPress will benefit from JIT compilation only in those WordPress Core functions that are constantly called, but honestly this is far from being considered a CPU-intensive task.
Comparing WordPress PHP 8 JIT Performance, a real case
In a playground environment we have compared a WordPress site with PHP8.2 with and without JIT.
The test site was chosen as a clear target due to its:
- Huge Page Generation Time: more than 2 seconds.
- Low database processing Time: 36 milliseconds.
This first screenshot with No JIT Compiler, shows a Generation Time of 2.3245 seconds:
After enabling the JIT Compiler:
The “Page Generation Time” with JIT enabled, shows 2.1387 seconds. Meaning a reduction of 8%
Is it worth activating PHP 8 JIT for WordPress?
To get this 8% of performance improvement, not always.
The fact is that you always have to keep in mind that the first execution is going to be slower. In this first execution, the code is compiled and its caching managed for subsequent calls.
If the PHP 8 JIT-compiled code is not reused across multiple requests,
For example, you could configure WP Super Cache to pre-cache your pages.
consider disabling JIT and
using a caching system that can pre-generate your pages.
If it’s not possible to use a cache system to pre-generate static HTML pages, such as for a membership site where pages are interactive and unique for each user, you could consider enabling the PHP 8 JIT compiler, which can dynamically compile PHP code for faster execution.
Remember WordPress’s Main Bottleneck Is Sometimes Its Database!!
In such cases, the vast majority of the waiting time does not come from the PHP execution time, but from the MySQL process time, which will not improve with the help of the JIT compiler. If this is your case, your alternative to improve the speed performance is an Object Cache for your data.
Read more in this post: Redis Object Cache for WordPress.
Is WordPress Compatible With PHP 8?
PHP 8 introduces significant changes that are not backward compatible and removes many features marked as deprecated in previous PHP 7.x releases.
The most significant breaking change in PHP 8 is the strict typing. Many built-in functions are now pickier about the Input they accept, and PHP 8 itself is more stringent about how the Input passes to functions. Issues that previously resulted in notices currently result in warnings, and issues that previously resulted in warnings now result in errors.
Another noteworthy compatibility problem can be warnings converted to error exceptions. There are a large number of PHP warnings changed to error exceptions in PHP 8.
The WordPress core team has worked since release 5.6 on all these code deprecations. But, considering that WordPress is never used isolated (we always install third-party themes and plugins), being able to run our WordPress base install on PHP 8 does not indicate “full” compatibility.
Is My WordPress Setup Compatible With PHP 8?
Wait. The state of PHP 8 support within the broader ecosystem (plugins, themes, etc.) is impossible to know. For that reason, our recommendation is to check your setup in a staging environment.
WordPress compatibility tools for developers
The PHP ecosystem produces several tools that can aid you during PHP upgrades, including:
- PHPCompatibility : it is a plugin for PHP CodeSniffer (an essential development tool that ensures your code remains clean and consistent). This plugin provides rules that will flag compatibility issues and suggest how to refactor your code.
- Rector: it is a tool that can perform some code refactoring for you. It helps with PHP upgrades, framework upgrades, and improves your code quality.
- Also, as a developer, although it is not a tool, consider having the PHP Migration Guides handy.
A WordPress PHP 8 compatibility checker
If you intend to address a compatibility test of a WordPress site, with all its plugins and themes, in this case, the best PHP 8 compatibility checker you can find is a test environment running with an exact copy of your production WordPress site. In other words, test your site in a Staging Environment.
If you do not have PHP 8 with your current provider, or your hosting does not have a Staging Environment, signup! in 10 seconds, we offer you FREE development servers.
At Wetopi, with your Free or paid Plan, you can change back and forth your PHP Engine from PHP 5.6 to PHP 8.3
Testing My WordPress Site In A Staging Server
Do You want to check PHP8 with your WordPress site?
We migrate your WordPress site — for free —
And don’t want to deal with the details?
- Login to your Wetopi and go to your site page.
- Open the “Menú options” of your production server and click the Clone option:
- In your new staging server: open the “Menu” options and the “Advanced”options section. There you can Switch on PHP 8 with a single click:
Our Recommendation:
When writing this article, PHP 8.3 is the most recent version of PHP. This latest PHP 8 release comes with several performance improvements and security enhancements. Upgrading the PHP engine of a WordPress CMS from version 7.4 to 8.3 can bring significant benefits, but it also requires testing.
Also, consider that PHP 7.4 has reached its end of life (since November 2022) and will no longer see security updates.
All in all, upgrading to PHP 8.3 can improve the performance of you website and security. Still, it is essential to test, in your Staging server, all of your plugins and themes, and ensure your code is compatible with the new PHP version to avoid issues.
Being said that our recommendation is:
— Start by testing the compatibility of your WordPress theme and plugins in a sandboxed or test environment —
Replace the old and non supported plugins
and
Upgrade your live site as soon as no issues arise.
Don’t you have an account on Wetopi?
Free full performance servers for your development and test.
No credit card required.