composer/xdebug-handler
Restart PHP CLI processes without loading Xdebug (unless xdebug.mode=off), avoiding slowdowns in tools like Composer. Creates a temporary ini with Xdebug commented out and relaunches the command, with env vars to allow Xdebug or inspect original ini paths.
Add the package via composer require composer/xdebug-handler. Then, in your CLI application’s entry point (e.g., bin/myapp), instantiate and invoke the handler early—before any heavy initialization:
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Composer\XdebugHandler\XdebugHandler;
$xdebug = new XdebugHandler('myapp');
$xdebug->check();
unset($xdebug);
// ... rest of app logic
This is the minimal setup. It automatically detects if Xdebug is loaded and not in xdebug.mode=off, and restarts the process without Xdebug—unless MYAPP_ALLOW_XDEBUG=1 is set. Start here if you want to avoid Xdebug’s performance penalty in long-running CLI tools (e.g., build scripts, workers, or PSR-15 console apps).
check() at the top of your main script; no extra configuration needed.symfony/process or proc_open), use Composer\XdebugHandler\PhpConfig to ensure Xdebug is excluded unless explicitly needed:
$config = new PhpConfig();
$options = $config->useStandard(); // Add [-n, -c, tmpIni] to command
$process = new Process(['php', ...$options, 'script.php'], ...);
XdebugHandler and override requiresRestart() and/or restart() to control when a restart happens (e.g., skip on --help, or inject additional ini overrides for phar.readonly).setLogger() with PSR-3 to surface restart status in logs—crucial for debugging in CI or production environments.php_ini_loaded_file() calls with XdebugHandler::getAllIniFiles() in restarted contexts to avoid reporting incorrect paths.-n vs -c nuance: Standard restart uses -n (skip scan dir) + -c (temp ini). Persistent mode sets PHPRC/PHP_INI_SCAN_DIR environment variables—this affects all subprocesses, not just the immediate restart. Choose carefully based on subprocess hygiene needs.xdebug.mode=off bypass: If Xdebug is loaded but xdebug.mode=off, no restart occurs. You’ll see a debug log like No restart ... Allowed by xdebug.mode.XDEBUG_HANDLER_DEBUG=2 to see where the temp ini is written and whether creation succeeded. Common failure: open_basedir or sys_temp_dir restrictions preventing temp file creation.MYAPP_ORIGINAL_INIS is a path-separated string: When using getRestartSettings()['inis'], the first entry is php_ini_loaded_file(), the rest are from php_ini_scanned_files().PhpConfig, Xdebug will reappear unless they also call xdebug-handler. This is the #1 gotcha—always pass useStandard() or usePersistent() options into subprocess calls.restart() to inject ini settings (e.g., phar.readonly=0). Consider copying into a temp dir first if packaging signed phars.CTRL+C—the parent ignores it. Don’t rely on parent-process cleanup for interactive signals.How can I help you explore Laravel packages today?