Website Without PHP
US
Menu

OPcache

Also known as: opcode cache

OPcache is a PHP feature that remembers your site's code in a ready-to-run form, so PHP does not have to prepare it again for every visitor.

PHP and versions Last updated:

OPcache is a PHPPHP is a programming language that builds your web pages on the computer that hosts your site, just before they reach the visitor. WordPress runs on it. feature that remembers your site’s code in a ready-to-run form, so PHP does not have to prepare it again for every visitor. A WordPressWordPress is free software for building and editing a website in your browser. It is written in PHP, so it builds each page when someone visits. page is built from dozens of files, so remembering them saves a lot of repeated work.

What is OPcache?

OPcache is a built-in PHP extension that keeps compiled scripts in memory, so PHP does not have to read and compile them on every request.

PHP does not run your source files directly. It first compiles each file into an intermediate form and then executes that. Without a cache, this happens again for every request and every file. OPcache stores the compiled result in shared memory, so the next request can skip the compile step.

The effect is that the same site uses less processor time per page view and answers faster, without any change to the code. It is not a page cache. It does not store finished pages, only the compiled code that produces them.

The settings that matter

A few settings in php.iniphp.ini is the settings file for PHP on your hosting. It sets limits, such as how much memory a script may use, how big an upload may be and if errors show. decide how OPcache behaves. opcache.enable turns it on. opcache.memory_consumption sets how much memory it may use. opcache.validate_timestamps and opcache.revalidate_freq control how often it checks whether a file has changed. On production servers, some hosts switch off timestamp checks for speed, which makes a reset necessary after each code change.

OPcache and your WordPress site

Most of the time you will not notice OPcache, and that is the point. You notice it in two situations. The first is when a site is slow and OPcache is off or too small. The second is when you update plugins or core files and the old behavior seems to stay, because the cache still holds the old compiled version.

During a PHP version update the cache is also relevant. Each PHP version has its own OPcache, and a restart of PHP-FPMPHP-FPM is a helper on your hosting that runs your site's PHP code as a separate job and hands the finished page back to the program that answers visitors. empties it. After a switch, the first requests are slower while the cache fills again.

How to check OPcache

Open a phpinfo page and look for the section “Zend OPcache”. It shows whether it is enabled, how much memory is used and how many scripts are cached. Some hostingWeb hosting is the service that keeps your website's files on a computer that is always online, so visitors can open your site at any time. panels show the same in the PHP settings. Remove the phpinfo page afterwards.

If it is disabled, ask your host to enable it. If the memory is nearly full, ask for a larger allocation. Do not tweak the values blindly on a shared serverShared hosting is a hosting plan where many websites share one computer. It is cheap and simple, but your host decides which PHP versions you can use., because the right numbers depend on how many files your sites load in total.

When to act

Look at OPcache when pages are slow for no clear reason, after a PHP update, or when changes to code do not show up. Treat it as one part of the picture, together with your PHP versionA PHP version is a numbered edition of PHP, like 8.3. Each edition is looked after for a limited time, then gets security fixes only, then nothing. and your hosting. A newer PHP branch is usually faster, and our PHP upgrade service takes care of the version and of checking that the cache works after the switch.

Frequently asked questions

Is OPcache the same as a page cache?

No. OPcache stores compiled PHP code. A page cache stores finished pages. They work at different levels and can be used together.

Is OPcache turned on by default?

OPcache ships with PHP, but it only works when the extension is loaded and enabled in the configuration. Most hosts take care of that. Check the phpinfo page for the OPcache section to be sure.

Why do I still see old code after an update?

OPcache may still hold the old compiled version of the file. A reload of PHP-FPM or an OPcache reset clears it. Some hosts do this automatically after a deploymentA deployment is the step that puts a new version of your website live for visitors, ideally automated, tested and easy to undo..

Can OPcache cause errors?

Rarely. If the memory reserved for OPcache is too small, it fills up and performance drops. The phpinfo page and your host's tools show how full it is.

Related pages

  1. Domain
  2. Check
  3. Result
  4. Report

Which PHP version does your site run?

Enter your domain. We read only what your site already sends in public: the headers and the top of the homepage. No scan, no login. We keep the domain and the result, never your IP address.