performance icon indicating copy to clipboard operation
performance copied to clipboard

Recommend PHP accelerators i.e., OPCache?

Open LukaszJaro opened this issue 3 years ago • 11 comments

Are PHP accelerators used often and beneficial to the performance of a WordPress site? If so would it be a good idea to include in the site health check?

PHP: There are various PHP accelerators available which can dramatically improve performance of your PHP files. This will apply to all PHP files, not just your WordPress installation. Search for PHP optimization for more information, f.e. APC or OPcache. The W3 Total Cache plugin, described below, offers integrated support for Memcache, APC and other Opcode caching. https://wordpress.org/support/article/optimization/#optimize-software

Some further reading https://wesleyzhang.me/do-you-need-op-cache/

LukaszJaro avatar Jul 25 '22 14:07 LukaszJaro

@LukaszJaro Good question! @manuelRod Curious for your thoughts here.

mxbclang avatar Jul 25 '22 14:07 mxbclang

Hello, @LukaszJaro thanks for opening this one up. As far as I can see, isn't OPCache enabled by default in modern PHP versions? +7.0? I could find the following article:

For many WordPress site owners, their server may already have the latest version of PHP installed. This means they already have OPcache automatically enabled to drastically speed up page load times for their site.

https://wp-rocket.me/blog/what-is-opcache/

Also this:

The real incentive for upgrading your PHP version is the promise of a performance boost. PHP 7.4 will deliver on that. PHP 7.4 will introduce preloading to PHP core. This is essentially done via an extension to Opcache, the software that stores precompiled script bytecode in shared memory. This helps eliminate the need for loading scripts on every request.

https://wpengine.com/blog/a-first-look-at-php-7-4/

If that's the case, maybe is a bit redundant to add a check for it, though I'm not 100% sure if that's the case.

manuelRod avatar Jul 26 '22 15:07 manuelRod

Thank you @manuelRod, that is great information! I'm in the process of finding out from my managed hosting provider if it is enabled or some alternative being used. So far I am not seeing it listed using php info, will report back once I have more data.

LukaszJaro avatar Jul 26 '22 21:07 LukaszJaro

Surprisingly my hosting provider(enterprise grade and running on NGINX, PHP 7.4) did not have any PHP accelerator method enabled. This is just one case so far where it was not enabled, I also have some cheaper shared hosting I can check and see what's enabled.

LukaszJaro avatar Jul 27 '22 16:07 LukaszJaro

I can confirm that not all hosting providers enable PHP accelerators such as OPCache by default. Plus, users could accidentally disable it in PHP extensions settings. I think this could be a helpful feature

merkys7 avatar Jul 31 '22 16:07 merkys7

What is the hosting you are using, and which PHP version? I'm curious. Is this something they can enable on request? In that case, I'm surprised they don't do it by default.

manuelRod avatar Aug 01 '22 14:08 manuelRod

I am a system engineer at Hostinger.com and I have enabled the OPCache PHP extension by default on PHP versions that supports OPCache. On my production WP site, I use 8.1 PHP with OPCache. The tests showed that with OPCache WP site could load faster. As user, you can navigate to control panel PHP selector section and enable/disable wanted PHP extensions such as OPCache,ACPU,etc. Usually, hosts enable OPCache by default.

merkys7 avatar Aug 01 '22 20:08 merkys7

I think the latest PHP supports OPCache or APC. https://www.cloudways.com/blog/integrate-php-opcache/ has one example of how OPCache affects site performance. We should add a site health check for this type of accelerator so end users get notice of it and if it's a disabled user's request to start it from the hosting provider.

I have made an extensive framework with a lot of fields and validation methods and enums to be able to talk to my database.

Without OPcache

When using this script without OPcache, I push 9000 requests in 2.8 seconds to the Apache server. It maxes out at 90-100% CPU for 70-80 seconds until it catches up with all the requests.

Total time taken: 76085 milliseconds(76 seconds)

With OPcache enabled

With OPcache enabled, it runs at 25-30% CPU time for about 25 seconds and never passes 25% CPU use.

Total time taken: 26490 milliseconds(26 seconds)

mukeshpanchal27 avatar Aug 02 '22 11:08 mukeshpanchal27

Verified on my cheaper shared hosting that opache is not enabled in cpanel but it's easy enough to enable with a click of a button.

That's two separate hosting companies I checked that don't have it enabled by default. Judging by the above it sounds like significant performance boost is possible depending on site.

I probably read over the WordPress performance recommendations a few times over the years https://wordpress.org/support/article/optimization/#optimize-software but it never clicked about the PHP accelerators so maybe having it in site health check will encourage more people to enable it.

LukaszJaro avatar Aug 02 '22 14:08 LukaszJaro

It seems then, that we need a new Site Health check :) @LukaszJaro do you want to expose this in the next perf weekly meeting? so we can get some feedback over there?

manuelRod avatar Aug 03 '22 15:08 manuelRod

Thanks @LukaszJaro and @manuelRod! If we want to propose this as a new health check, can you please update the issue with the content from the new module proposal issue template? Once that's done, we can work on getting this scheduled for discussion in a future performance chat. Thank you!

mxbclang avatar Aug 03 '22 15:08 mxbclang

Given the lack of traction here I am inclined to close this as a maybelater.

Note that APCu is already checked in Site Health as part of the persistent object cache check (added in https://core.trac.wordpress.org/changeset/53955)

Also, this check isn't really actionable for the user. They're unlikely to being able to change their hosting setup.

swissspidy avatar Jan 27 '25 17:01 swissspidy