Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawning a second PHP process breaks the debugger #231

Closed
johnbillion opened this issue Jan 24, 2018 · 7 comments
Closed

Spawning a second PHP process breaks the debugger #231

johnbillion opened this issue Jan 24, 2018 · 7 comments

Comments

@johnbillion
Copy link

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"
@johnbillion
Copy link
Author

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

@tdchien
Copy link

tdchien commented Feb 27, 2018

I'm same too. Finding a way for this

@esther-86
Copy link

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

@btry
Copy link

btry commented May 1, 2018

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.

@yuvanathan
Copy link

yuvanathan commented May 16, 2018

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

@jonathanjfshaw
Copy link

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

@zobo
Copy link
Contributor

zobo commented Jan 29, 2022

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

@zobo zobo closed this as completed Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants