From bbf33b836026cbe9fb9e7c76291dcb133b7144e2 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 10 Aug 2026 00:57:19 +0900 Subject: feat(xdebug): switch Xdebug off in the PHP worker Composer restarts itself with Xdebug unloaded because Xdebug makes PHP several times slower. Xdebug is never loaded into this process, so what needs dealing with is the PHP worker: it is spawned with `-d xdebug.mode=off` and `XDEBUG_MODE=off` (Xdebug reads the environment variable first and lets it override every ini setting), which makes its module init return before it installs any executor, compile, error or opcode hook. Rewriting the ini files and re-executing, the way xdebug-handler does, would additionally cover Xdebug 2, which hooks unconditionally and has no equivalent setting. That is not worth its machinery here: Xdebug 2 caps out at PHP 7.4, while every PHP version Composer supports can run Xdebug 3. What remains of XdebugHandler is small enough to live beside the worker it governs, so its crate is gone and its callers inline it. isXdebugActive answers false without asking PHP whenever the worker is switched off, so a command that needs no PHP does not spawn one just for the Xdebug warning; diagnose reports what the worker measures instead, which still surfaces an Xdebug that ignores the setting. PlatformRepository has no unloaded extension to restore, since switching the mode off leaves it loaded. COMPOSER_ORIGINAL_INIS is neither written nor read: it exists so a restarted process can name the ini files it replaced, and IniHelper can report the worker's own. IniHelperTest injects through that variable, so none of its cases are ported. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/repository/platform_repository.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'crates/shirabe/src/repository') diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 7e123151..3e1f35ec 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -20,11 +20,10 @@ use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_rpc::PlatformInfo; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn, - array_slice_strs, explode, get_class, implode, in_array_strict, is_string, php_regex, - str_replace, str_starts_with, strpos, strtolower, var_export, + array_slice_strs, explode, get_class, implode, is_string, php_regex, str_replace, + str_starts_with, strpos, strtolower, var_export, }; use shirabe_semver::constraint::SimpleConstraint; -use shirabe_xdebug_handler::XdebugHandler; use std::sync::{LazyLock, Mutex}; static LAST_SEEN_PLATFORM_PHP: LazyLock>> = LazyLock::new(|| Mutex::new(None)); @@ -303,17 +302,10 @@ impl PlatformRepository { } // Check for Xdebug in a restarted process - if !in_array_strict( - "xdebug".to_string(), - &loaded_extensions - .iter() - .map(|s| PhpMixed::String(s.clone())) - .collect::>(), - ) && let Some(xdebug_pretty_version) = XdebugHandler::get_skipped_version() - && !xdebug_pretty_version.is_empty() - { - self.add_extension("xdebug", &xdebug_pretty_version)?; - } + // PHP re-adds the extension `XdebugHandler::getSkippedVersion()` names, since its restart + // runs on an ini file with Xdebug commented out. The worker is instead started with + // `xdebug.mode=off` (see docs/dev/xdebug.md), which leaves the extension loaded, so it is + // already among $loadedExtensions. // Another quick loop, just for possible libraries // Doing it this way to know that functions or constants exist before -- cgit v1.3.1-4-g156e