Vscode-php-debug: Spawning a second PHP process breaks the debugger

Created on 24 Jan 2018  路  6Comments  路  Source: xdebug/vscode-php-debug

I've determined the root cause of #154 and produced a tiny reproducible example. It's not related to PHPUnit, it's caused by a call to system() which spawns a second PHP process and causes the VS Code debugger to malfunction.

Running the test case below will cause the debugger to get "stuck", with two requests appearing in the call stack panel and nothing else functional apart from the Stop button.


// 1.php
<?php
echo 'Running 1.php' . PHP_EOL;
system( 'php 2.php' );
echo 'Completed 1.php' . PHP_EOL;
// 2.php
<?php
echo 'Running 2.php' . PHP_EOL;

Steps to reproduce:

  1. Place a breakpoint on the last line of 1.php and launch the VS Code debugger.
  2. Run php 1.php on the command line
  3. Observe that the debugger locks up with two requests showing in the call stack panel and nothing else functional.

PHP version: 7.1.0
XDebug version: 2.5.5
Adapter version: 1.12.1

Your launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 8999,
            "log": true
        }
    ]
}

XDebug php.ini config:

[xdebug]
zend_extension=/Users/john/.phpbrew/php/7.1/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.idekey = john-xdebug
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 8999q
xdebug.remote_log = "/sites/x/php/xdebug.log"

Most helpful comment

I'm posting my answer to what I did to be able to debug my test code. If you can launch the second php with a different remote port, it might solve your problem.
https://stackoverflow.com/questions/49148551/how-can-i-get-xdebug-to-run-with-phpunit-on-the-cli-in-windows-using-vscode/49207236#49207236

All 6 comments

Oh, I guess this might be a duplicate of #164.

I'm same too. Finding a way for this

I'm posting my answer to what I did to be able to debug my test code. If you can launch the second php with a different remote port, it might solve your problem.
https://stackoverflow.com/questions/49148551/how-can-i-get-xdebug-to-run-with-phpunit-on-the-cli-in-windows-using-vscode/49207236#49207236

Hi

I observe the same behaviour when running unit tests with atoum. This framework runs a master process, creating a process for each test method. Therefore I got at least 2 PHP processes running. It seems that sometimes I can debug, but in most of my attempts, I forced to stop the debugger or the unit tests currently being debugged.

I also observe the same when I run my main project. This is a web application, and most of the time there are 2 nearly concurrent calls to the LAMP server. In this case too, a debug session freezes all requests, but if I try 2 or 3 times, the debug session runs correctly.

This worked. I added php_value xdebug.remote_port 9001 in 2nd site's directory .htaccess.

I'm posting my answer to what I did to be able to debug my test code. If you can launch the second php with a different remote port, it might solve your problem.
https://stackoverflow.com/questions/49148551/how-can-i-get-xdebug-to-run-with-phpunit-on-the-cli-in-windows-using-vscode/49207236#49207236

This also worked for me, adding a second configuration listening on 8000 and then:
'php -d xdebug.remote_port=8000 "vendor/bin/phpunit" "anyphpunitargument"'

You can run both configurations more easily if you use a compound configuration:
https://code.visualstudio.com/docs/editor/debugging#_multitarget-debugging

I use Lando as my development environment, which makes this solution a bit easier to implement, and I added it to their docs:
https://github.com/lando/lando/pull/1107

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NerijusNoreika picture NerijusNoreika  路  12Comments

camrongodbout picture camrongodbout  路  5Comments

QwertyZW picture QwertyZW  路  9Comments

eghoff1 picture eghoff1  路  10Comments

lirondu picture lirondu  路  11Comments