Fix: Reset PHP OPcache after update to prevent 500 errors#1288
Open
Sebbeben wants to merge 1 commit intoPart-DB:masterfrom
Open
Fix: Reset PHP OPcache after update to prevent 500 errors#1288Sebbeben wants to merge 1 commit intoPart-DB:masterfrom
Sebbeben wants to merge 1 commit intoPart-DB:masterfrom
Conversation
After cache warmup, create a temporary PHP script in the public directory and invoke it via HTTP to reset OPcache in the PHP-FPM context. This prevents stale bytecode from causing 500 errors when the progress page refreshes after code has been updated. The reset is also performed after rollback and during restore. Uses a random token in the filename for security, and the script self-deletes after execution with a cleanup in the finally block.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1288 +/- ##
============================================
- Coverage 55.42% 55.31% -0.12%
- Complexity 8266 8277 +11
============================================
Files 610 610
Lines 26513 26566 +53
============================================
Hits 14694 14694
- Misses 11819 11872 +53 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Problem
After the update manager completes an update (git checkout, composer install, cache clear/warmup), PHP-FPM may still serve stale bytecode from OPcache. This causes 500 errors when the progress page auto-refreshes, because the old cached container tries to instantiate classes with changed constructor signatures.
Example error seen after updating from v2.7.1 to v2.8.1:
This affects any native git installation running PHP-FPM with OPcache enabled (which is the default and recommended configuration).
Solution
Added an OPcache reset step after cache warmup in the update, restore, and rollback flows. The approach:
public/(e.g.,_opcache_reset_<random>.php)http://127.0.0.1/thenhttp://localhost/) to triggeropcache_reset()in the PHP-FPM contextfinallyblockWhy this approach?
opcache_reset()from CLI only affects the CLI process, not PHP-FPMcachetoolmay not be installedChanges
src/Services/System/UpdateExecutor.php:resetOpcache()private method