Fix symlink-induced double-load crash in WP Cloud E2E test#148
Merged
Conversation
When wp-content is a symlink (like in the WP Cloud E2E test layout), PHP can load utils.php and class-http-server.php twice: once via Composer's files/classmap autoload (resolved realpath) and once via export.php's require_once (symlink path). With the default opcache.revalidate_path=0, require_once doesn't resolve symlinks for deduplication, so the same physical file gets included from two paths and function/class declarations collide. Guard both requires with function_exists/class_exists checks so the redundant include is skipped regardless of path resolution.
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.
Summary
The
import-38-flatten-wpcloudE2E test creates a WP Cloud-like layout wherewp-contentis a symlink to an external directory. When PHP-FPM serves requests through this layout,utils.phpgets loaded twice — once by Composer'sfilesautoload (using the resolved realpath) and once byexport.php'srequire_once(using the symlink path). With the defaultopcache.revalidate_path=0, PHP doesn't resolve symlinks forrequire_oncededuplication, so the second load triggersCannot redeclare build_pdo_dsn().This showed up as a flaky failure on trunk — only PHP 8.1 failed in the latest CI run because the exact symlink resolution behavior varies across PHP versions and opcache states. The same bug would affect any real WP Cloud site where
wp-contentis symlinked away from ABSPATH.The fix guards the
require_oncecalls inexport.phpwithfunction_exists/class_existschecks, so the redundant include is skipped when the Composer autoloader already loaded the files from a different path.Test plan
import-38-flatten-wpcloudpasses on all PHP versions in CI (was failing on PHP 8.1)