Skip to content

XdebugHandler->check() should be called very early #175

Open

Description

@staabm

I did some testing with xdebug-handler. my test.php looks like

<?php

use Composer\XdebugHandler\XdebugHandler;

require_once __DIR__ . '/vendor/autoload.php';

var_dump(extension_loaded('xdebug'));
echo "booting a second...\n";
sleep(1);

$xdebug = new XdebugHandler('myapp');
$xdebug->check();
unset($xdebug);

var_dump(extension_loaded('xdebug'));
echo "running a second...\n";
sleep(1);

what I realized is, that the logic which is running before $xdebug->check(); is executed twice.

➜  xdebug-handler git:(pcntl_exec) ✗ php test.php
bool(true)
booting a second...
bool(false)
booting a second...
bool(false)
running a second...

this means a application should invoke $xdebug->check(); very very early in the process, because the bootstrap logic is executed twice in the restarting case.

if you e.g. have a symfony-console application and do the $xdebug->check(); only after the command has been determined and dispatched, I can see PHPStan is loosing ~0.04seconds in the process. this might easily add more time when you take this perf hit on every worker-process along the way.

I wonder whether thats something which need to be documented somewhere.

Activity

  1. changed the title [-]`XdebugHandler->check()` should be verify early[/-] [+]`XdebugHandler->check()` should be called very early[/+] on Oct 18, 2026
  2. johnstevenson commented on Oct 18, 2026

    @johnstevenson
    Member

    what I realized is, that the logic which is running before $xdebug->check(); is executed twice.

    Err, well yes, it would have to.

    this means a application should invoke $xdebug->check(); very very early in the process,

    It depends what the application wants to do though and whether it needs certain information before it can decide. The readme contains a simplified example which does not restart on a help command https://github.com/composer/xdebug-handler#example

    It also points to some Examples that are used in the functional tests but can also be run independently to illustrate the behaviour in different scenarios. So you could use app-basic.php instead of your test script:

    cd tests/App
    php app-basic.php --display
    
    app-basic[7672] start
    logger[7672] Checking APP_BASIC_ALLOW_XDEBUG
    logger[7672] The Xdebug extension is loaded (3.5.3) xdebug.mode=coverage
    logger[7672] Process restarting (APP_BASIC_ALLOW_XDEBUG=internal|3.5.3|0|*|*)
    logger[7672] Running: [C:\php-8.4.26\php.exe, -n, -c, C:\***\Local\Temp\suh2CE2.tmp, app-basic.php]
      app-basic[2784] start
      logger[2784] Checking APP_BASIC_ALLOW_XDEBUG
      logger[2784] Restarted (129 ms). The Xdebug extension is not loaded
      app-basic[2784] working [NO XDEBUG] The Xdebug extension is not loaded
      app-basic[2784] working [active] false
      app-basic[2784] working [skipped] 3.5.3
      app-basic[2784] working [env] PHPRC unset
      app-basic[2784] working [env] PHP_INI_SCAN_DIR unset
      app-basic[2784] working [ini] C:\php-8.4.26\php.ini
      app-basic[2784] working [settings] tmpIni=C:\***\Local\Temp\suh2CE2.tmp
      app-basic[2784] working [settings] scannedInis=false
      app-basic[2784] working [settings] scanDir=false
      app-basic[2784] working [settings] phprc=false
      app-basic[2784] working [settings] inis=C:\php-8.4.26\php.ini
      app-basic[2784] working [settings] skipped=3.5.3
      app-basic[2784] finish
    logger[7672] Restarted process exited 0
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions