Skip to content

Add OPCache support #2400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2025
Merged

Add OPCache support #2400

merged 5 commits into from
Jul 22, 2025

Conversation

zaerl
Copy link
Collaborator

@zaerl zaerl commented Jul 22, 2025

This PR is created from #2290
The Github UI is stuck using that PR, so a new PR has been created.
https://a8c.slack.com/archives/C04BURZDHFH/p1753189537944499

Motivation for the change, related issues

Related to #2251

With this PR, we are adding support for OPCache by introducing a new WITH_OPCACHE argument, true by default.

Implementation details

The OPCache library is always compiled as a dynamic library. Once #2248 is merged, we can proceed to use the dynamic library generated instead of forcing a static compilation by patching ext/opcache/config.m4.

Caching mechanism

The OPCache .m4 file performs a series of tests.

Feature checks 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4
OPCACHE_FILE_CACHE
HUGE_CODE_PAGES
JIT
MPROTECT
SHM_IPC
SHM_MMAP_ANON
SHM_MMAP_ZERO
SHM_MMAP_POSIX
SHM_MMAP_FILE

In this PR, we force the Autoconf to recognize the mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); emulated shared (anonymous) memory by renaming have_shm_mmap_anon (renamed to php_cv_shm_mmap_anon in PHP 8.4).

Additional

Starting with Python 3.12, distutils was removed from the standard library after being deprecated in Python 3.10. Here, we force the last version to ensure that node-gyp/gyp/gyp_main.py does not crash during compilation because it does not find the module.

Testing Instructions (or ideally a Blueprint)

First test

Open phpinfo.php and search for "Zend OPCache". It should be "Up and Running" and "OK" on startup

Second test

Try this blueprint (https://gist.github.com/zaerl/3e60bff32e1e915d5acc509bd50e9762). It will load WordPress +20 times so it will not open immediately.
"Cached" should be true, all the GET responses 200 OK. The opcache_enabled field will be false. It is a well-known PHP feature bug. Now open packages/php-wasm/universal/src/lib/php.ts and comment out these two lines:

// 'opcache.file_cache_only = 1',
// 'opcache.file_cache_consistency_checks = 1',

The same page will show more details and an hit rate ~75%. Now visit wp-admin, open some page. Go back to opcache.php, it should show ~90% or better.

@zaerl zaerl requested a review from a team as a code owner July 22, 2025 13:37
@zaerl zaerl requested review from adamziel and brandonpayton July 22, 2025 13:49
Copy link
Collaborator

@adamziel adamziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing work @zaerl, thank you!

@zaerl zaerl merged commit e0b8815 into trunk Jul 22, 2025
1 check passed
@zaerl zaerl deleted the add/opcache branch July 22, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants