Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xdebug set cookie XDEBUG_SESSION too many times

I use remote debug with PhpStorm, xdebug and nginx + php-fpm. Nginx repsond with 502 error code (Bad Gateway) when I pass XDEBUG_SESSION_START=my_ide_key in request GET parameter. At the same time my code breakpoints in IDE work fine. When I don't pass XDEBUG_SESSION_START parameter nginx respond with well-formatted HTML and code 200. But obvious without this parameter it is no debugging.

In nginx error log I see notifications about to big header received from upstream. I try to dump communication between php-fpm and nginx and just one different thing is one Set-Cookie header:

Set-Cookie: XDEBUG_SESSION=666; expires=Mon, 16-Sep-2013 16:07:28 GMT; path=/

I try to find when this headers appears in response. And I found that in my smarty plugin Smarty_Internal_Template destructors (after last code line of my start up script) if I call headers_list() I see growing up amount of Set-Cookie headers (equal destructor calls and Set-Cookie headers amount). I am sure that there is no one explicit header('Set-Cookie: XDEBUG_SESSION=...') call in my code. I try to upgrade and downgrade xdebug version but still have same behavior. Place code remove_header('Set-Cookie') at Smarty_Internal_Template solves my problem but that is ugly hack!

Any ideas about this strange situation?

like image 552
Ivan Velichko Avatar asked Sep 16 '13 15:09

Ivan Velichko


People also ask

What port is xdebug listening on?

Port 9003 is the default for both Xdebug and the Command Line Debug Client.


1 Answers

I would suggest not using XDEBUG_SESSION_START in this case. To me it looks like XDEBUG_SESSION_START is triggering some code execution on the server side to set the cookie. And that is interfering with smarty template code.

In all of my experience with PHPStorm, I have found that the best way to turn on xdebug is through the bookmarklet, which you can generate here:

https://www.jetbrains.com/phpstorm/marklets/

The bookmarklet sets the cookie in the browser itself. So, no code is executed in the server to set XDEBUG_SESSION and path variables and that could reduce or eliminate the interference with smarty code.

Also, one tip with PHPStorm is to make sure that the PHPStorm is up and running and the network connection is working properly between PHPStorm and php-fpm (I presume that is what you are using in combination with nginx).

If php-fpm cannot connect to PHPStorm, in my experience, the code will eventually execute on the server but it will be very slow.

There have been a few times when I have seen this wrongly as a performance problem and wasted lots of time.

like image 182
Devang Mehta Avatar answered Sep 30 '22 05:09

Devang Mehta