Can I connect the debugger to a PHP process started by another script (Windows)?

I have a test script that runs another PHP file asynchronously...

        $cmd = <<<EOT
cmd /c php -f="$script" $args
EOT;
$WshShell = new COM('WScript.Shell');
$WshShell->Run($cmd, 0, false);

This might be a long shot, but I'm wondering if there's something I can add to the command line that will allow me to debug the second script inside PHPStorm?

0
1 comment

Hi there,

You can always set xdebug.remote_autostart = 1 in your php.ini and xdebug will try to debug every single script (which means approx 1 sec delay if it fails to connect to debug client .. so it's not really suitable for daily usage/normal script execution).

You can also pass that as a parameter to the php executable (http://php.net/manual/en/features.commandline.options.php) using -d parameter -- this way it will affect that process/execution only.

NOTE: If you use "PHP Script" Run/Debug Configuration in PhpStorm (which is meant for running/debugging PHP files in CLI mode) .. you will see what params and how PhpStorm itself uses them. For example, for local execution on my Windows 10 computer it adds "-dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1"

P.S. If you need to debug 2 scripts at a time in PhpStorm (e.g. you are debugging first (e.g. index.php) which calls another one (e.g. task.php)) then you also need to increase "max simultaneous connections" limit in PhpStorm settings (by default it's just 1) -- just use search box in the Settings screen to find it -- will be on the same page as other PHP debug settings)

1

Please sign in to leave a comment.