Fix GH-13989: Allow opcache.file_cache_only=1 without source files#21236
Open
pronskiy wants to merge 1 commit intophp:masterfrom
Open
Fix GH-13989: Allow opcache.file_cache_only=1 without source files#21236pronskiy wants to merge 1 commit intophp:masterfrom
pronskiy wants to merge 1 commit intophp:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
opcache.file_cache_only=1is enabled and the file cache is warm, PHP currently requires source files to exist on disk even though it serves compiled opcodes from cache. This prevents legitimate deployment workflows where source code is stripped from the final image (e.g., Docker, PHAR, WASM).This PR makes PHP fall back to the file cache when source files are missing, instead of failing with "Could not open input file" or "Failed opening required".
Changes
sapi/cli/php_cli.c-- Whenopcache.file_cache_only=1is set and the script file doesn't exist, defer to opcache instead of immediately failing. The original "Could not open input file" error is preserved when opcache is not involved.ext/opcache/ZendAccelerator.c-- Two changes:file_cache_compile_file(): Try loading from file cache before attempting to open the source file. Paths are canonicalized viaexpand_filepath_with_mode(CWD_EXPAND)so that./foo.php,bar/../foo.php, and/app/foo.phpall resolve to the same cache entry.persistent_zend_resolve_path(): Infile_cache_onlymode, when the original resolver fails (file missing), return the canonicalized path so the file cache can look it up.ext/opcache/zend_file_cache.c-- Whenvalidate_timestamps=1and the source file is missing (timestamp 0), serve from cache instead of invalidating it.Limitations
Test plan
Closes GH-13989.