Skip to content

Opcache: Introduce ABI-based versioning for file cache portability #19123

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iamacarpet
Copy link
Contributor

Hello @dstogov and team,

This PR proposes a new versioning mechanism for the file-based opcache to improve its portability across different patch versions of PHP (e.g., 8.5.x) and minor system library changes.

The Problem

Currently, the file cache is versioned using zend_system_id, which is highly sensitive to minor changes in the environment, such as updates to system libraries or patch-level changes in the PHP version itself.

This fragility makes pre-generated, read-only opcaches difficult to use in modern containerized platforms like Google App Engine and Cloud Run. These platforms often perform automatic base image updates, which can change zend_system_id and invalidate an otherwise perfectly valid opcache, negating the performance benefits.

The Proposed Solution

To address this, this change introduces an "ABI hash" for the file cache. During the build process, it calculates a CRC32 checksum of the header files that define the core data structures used by opcache (e.g., zend_op, zval, zend_string, zend_function, zend_class_entry, etc.).

This hash is then used as part of the cache key instead of the more volatile zend_system_id. The result is a cache key that only changes when the underlying data structures (the ABI) actually change, which typically only happens between minor PHP versions (e.g., 8.5 vs 8.6).

Benefits

  • Improved Portability: Opcache file caches become portable across builds with identical ABIs, even if the PHP patch version or system libraries differ.
  • Enhanced Performance on Managed Platforms: This significantly improves the effectiveness of pre-warmed, read-only caches in environments with automatic base image updates, leading to better cold-start performance and reduced CPU usage.

This change is a continuation of the work started in #16551 and #16979 to optimize opcache for modern, ephemeral environments.

I believe a change of this nature will likely require an RFC. I'm happy to start that process and would appreciate any initial feedback on this approach.

Thank you for your time and consideration.

Regards,

iamacarpet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant