Skip to content

Spawning a second PHP process breaks the debugger #231

Closed

Description

@johnbillion

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"

Activity

  1. johnbillion commented on Jan 24, 2018

    @johnbillion
    Author

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

  2. tdchien commented on Feb 27, 2018

    @tdchien

    I'm same too. Finding a way for this

  3. esther-86 commented on Mar 10, 2018

    @esther-86

    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

  4. btry commented on May 1, 2018

    @btry

    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.

  5. yuvanathan commented on May 16, 2018

    @yuvanathan

    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

  6. jonathanjfshaw commented on Jul 18, 2018

    @jonathanjfshaw

    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:
    lando/lando#1107

  7. zobo commented on Jan 29, 2022

    @zobo
    Contributor

    Old issue. The handling of parallel connections has been reworked a lot in this time. Closing, please reopen with latest log if issue persists.

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