Fix Xdebug not starting on a normal page load on the native PHP runtime#4086
Open
juanmaguitar wants to merge 4 commits into
Open
Fix Xdebug not starting on a normal page load on the native PHP runtime#4086juanmaguitar wants to merge 4 commits into
juanmaguitar wants to merge 4 commits into
Conversation
Native PHP never set xdebug.start_with_request, so Xdebug fell back to its own default (trigger), requiring XDEBUG_TRIGGER/XDEBUG_SESSION on every request. The sandbox runtime doesn't have this restriction, and the docs promise "navigate to your site to trigger the breakpoints" — so this was a silent regression for the one site a user explicitly enables Xdebug on.
Collaborator
📊 Performance Test ResultsComparing dfc0d37 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
wojtekn
approved these changes
Jul 7, 2026
wojtekn
left a comment
Contributor
There was a problem hiding this comment.
The code change looks reasonable. Good catch, thanks for the fix.
| // https://xdebug.org/docs/all_settings#start_with_request. Studio's | ||
| // Xdebug is already an explicit, one-site-at-a-time opt-in, so once | ||
| // it's on we want every request on that site to start a debug | ||
| // session — matching the sandbox (php-wasm) runtime |
Contributor
There was a problem hiding this comment.
Could we make this comment more concise?
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.
Related issues
Fixes #4087
Proposed Changes
Enabling Xdebug on a site is already an explicit, per-site, mutually-exclusive opt-in — only one site can have it on at a time. The docs (https://developer.wordpress.com/docs/developer-tools/studio/xdebug/) say that once it's on, you just "navigate to your site in the browser to trigger the breakpoints." That's true on the sandbox (Playground/PHP-WASM) runtime, but not on the native PHP runtime (default since Studio 1.13): a normal reload does nothing, and you need
?XDEBUG_TRIGGER=1or the Xdebug Helper browser extension for the debugger to actually break.Root cause: on native, Studio sets
xdebug.mode=debugbut never setsxdebug.start_with_request, so Xdebug falls back to its own default, which resolves totriggerformode=debug(https://xdebug.org/docs/all_settings#start_with_request). The sandbox runtime doesn't hit this because it goes through@php-wasm/xdebug-bridge, a different code path that isn't gated on the trigger. It looks likestart_with_requestwas simply never carried over when native became the default runtime.This PR sets
xdebug.start_with_request=yeswhenever Xdebug is enabled on the native runtime, restoring "navigate to your site → breakpoints fire" for the one site that has it explicitly turned on. Trade-off: Xdebug will now attempt a connection on every request to that site (AJAX, heartbeat, cron), not just triggered ones — same as the sandbox runtime already does today, and scoped to a single opt-in site.Was leaving
start_with_requestat its default intentional, or a side effect of the native migration? I think we should keep the behavior documented in the docs and avoid extra steps for the final user to enable X-Debug on a site.Testing Instructions
Follow the setup steps at https://developer.wordpress.com/docs/developer-tools/studio/xdebug/ (IDE config, etc.), then:
?XDEBUG_TRIGGERor the Xdebug Helper extension?XDEBUG_TRIGGER=1to the URL, or use the Xdebug Helper browser extension to turn debugging on for the request — because Xdebug'sstart_with_requestsetting defaults totrigger, so it only starts a session when explicitly triggered (see https://xdebug.org/docs/all_settings#start_with_request)Also covered by a new unit test:
apps/cli/lib/native-php/tests/config.test.ts.Pre-merge Checklist
How AI was used in this PR
Investigated with Claude Code: traced the regression to
apps/cli/lib/native-php/config.ts, confirmed it against a live native-runtime site (Xdebug's DBGp<init>handshake only fired with?XDEBUG_TRIGGER=1, never on a plain reload), wrote the one-line fix + a unit test, and verified end-to-end (lint, typecheck, unit test, and a live re-test confirming the handshake now fires on a plain request) before opening this PR. All findings and the fix were reviewed by me before submitting.