You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(opcache): refresh() unlinks the just-written patched binary when shared memory + file cache are both active #252
Found while building the SHM integration coverage for #125 (PR #251). In a process running with SHM active plus opcache.file_cache (the hybrid mode, not file_cache_only), BinaryCacheFile::refresh() cannot deliver its documented "next include picks the patched binary up": its save-then-invalidate ordering self-destructs.
Verified empirically on PHP 8.4.19 and against php-src:
opcache_invalidate($path, true) with opcache.file_cache set calls zend_file_cache_invalidate(), which unlinks the .bin — deleting the patched binary save() wrote a moment earlier. The subsequent include recompiles the original source (observed: bin-exists-after-refresh=false, re-include returns the unpatched value), and the patch is lost pool-wide (any FPM worker would re-cache the original).
Reordering to invalidate-then-save is necessary but not sufficient for same-process pickup: with the default opcache.revalidate_path=0, the invalidated hash entry short-circuits path resolution in persistent_compile_file(), so zend_file_cache_script_load() bails on the unresolved opened_path and the source is recompiled. With opcache.revalidate_path=1 the invalidate-then-save ordering works in-process (verified); a fresh process picks the patched bin up with default settings either way.
Under opcache.file_cache_only=1 (the mode RefreshWorkflowTest proves) opcache_invalidate returns false and touches nothing — the existing behavior and docs remain correct there.
Fix shape (verified during the investigation)
Reorder refresh() (src/OpCache/BinaryCacheFile.php): invalidate first, then save() — so the unlink hits the stale binary, not the patched one.
Document the same-process pickup caveat (opcache.revalidate_path=1, or a fresh worker) in docs/opcache-binary.md's "Refresh and shared memory" section and the refresh() docblock.
Activity