Every time someone visits a PHP page, PHP reads the code files and translates them into an internal format before running them. OPcache keeps that translation in memory and reuses it, so later visits skip that work. Here it exists but ships switched off: you switch it on in Select PHP Version. It helps mostly when the code is large, such as an application with many files or a WordPress loaded with plugins.
Switching it on and confirming
| 1 |
In cPanel, open Select PHP Version (the Software section) and pick the version the site uses. Every PHP version has its own list of enabled extensions.
|
|
| 3 |
Confirm with a file containing <?php phpinfo(); in the site folder: a section called Zend OPcache should appear. Delete the file straight afterwards.
|
|
| 4 |
Measure again. The gain shows in the response time of pages that do not come from the page cache. See high TTFB.
|
|
What to expect, and what not
| Situation |
What OPcache does |
| A site with a well-set page cache |
Little: most visits never reach PHP. See LiteSpeed Cache. |
| Pages that cannot be cached (shop, members area, dashboard) |
A lot: every visit runs PHP, and reading and translating the code is saved. |
| A large application (framework, shop) |
Quite a bit: it has many files to read on every request. See getting a Laravel application running. |
| A slow database |
Nothing. OPcache only deals with the code, not the queries. See slow queries. |
Why my changes do not show
With OPcache on, PHP keeps the code and only checks again whether the file changed every so often (the interval is opcache.revalidate_freq, which the PHP documentation gives as a few seconds by default). So an edit may take a moment to appear. If a long time has passed and you still see the old version, the cause is rarely OPcache. Check, in this order:
| 2 |
The site’s page cache (the plugin, or a service in front). Run “Purge All”.
|
|
| 3 |
Did you edit the right file? The site folder may hold another copy, or a child theme may take priority.
|
|
| 4 |
Only then OPcache. To rule it out, untick the box in Select PHP Version, repeat the test and tick it again. If the difference disappears, OPcache was the culprit, and you can keep it off while you work on the code.
|
|
|
Do not leave it on for a site you are coding every minute without allowing for the delay. Many developers switch it on only in production. And if a plugin or an application generates PHP files and runs them straight away, old code may be seen for an instant.
|
|
Switched OPcache on and it does not show in phpinfo, or the site got worse? Send us the address and the PHP version.
Open a support ticket
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon) See plans |