Xdebug has set the XDEBUG_SESSION cookie too many times

I am using remote debugging with PhpStorm, xdebug and nginx + php-fpm. Nginx repsond with error code 502 (Bad Gateway) when I pass XDEBUG_SESSION_START=my_ide_key in a GET request. At the same time, my code breakpoints in the IDE work fine. When I do not pass the XDEBUG_SESSION_START parameter, nginx responds with well-formatted HTML and 200 code. But it is obvious that without this parameter there is no debugging.

In the nginx error log, I see notifications of a large header received from the upstream. I am trying to reset the connection between php-fpm and nginx, and only one thing is one Set-Cookie header:

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

I am trying to find when these headers appear in response. And I found that in my smarty plugin Smarty_Internal_Template destructors (after the last line of code in my script run), if I call headers_list() , I see a growing number of Set-Cookie headers (equal destructor calls and a number of Set-Cookie headers). I am sure that in my code there is no explicit call to header('Set-Cookie: XDEBUG_SESSION=...') . I am trying to upgrade and downgrade xdebug but still have the same behavior. The place code remove_header('Set-Cookie') at Smarty_Internal_Template solves my problem, but it's an ugly hack!

Any ideas on this weird situation?

+6
source share
1 answer

I would suggest not using XDEBUG_SESSION_START in this case. For me it looks like this: XDEBUG_SESSION_START runs some server-side code execution to set a cookie. And this interferes with the pluggable code template.

Throughout my experience with PHPStorm, I have found that the best way to enable xdebug is through the bookmarklet, which you can create here:

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

The label sets the cookie in the browser itself. Thus, the server does not execute the code to set XDEBUG_SESSION and path variables, which can reduce or eliminate interference using the smarty code.

In addition, one tip with PHPStorm is to make sure that PHPStorm is running and the network connection is working fine between PHPStorm and php-fpm (I assume this is what you use in conjunction with nginx).

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

There were several times when I saw this incorrectly as a performance problem and spent a lot of time.

+1
source

Source: https://habr.com/ru/post/953932/


All Articles