简体   繁体   English

Docker PHP 与 Xdebug 3 env XDEBUG_MODE 不工作

[英]Docker PHP with Xdebug 3 env XDEBUG_MODE doesn't work

I'm trying to config Xdebug 3 in PHP container, and set XDEBUG_MODE env variable to off according with documentation https://xdebug.org/docs/all_settings#mode but xdebug_info() shows that mode=develop .我正在尝试在 PHP 容器中配置Xdebug 3 ,并根据文档https://xdebug.org/docs/all_settings#modeXDEBUG_MODE变量设置为off ,但xdebug_info()显示mode=develop How to fix?怎么修?

Dockerfile: Dockerfile:

FROM php:7.4.11-fpm
…
ENV XDEBUG_MODE=off
ENV XDEBUG_CONFIG=""
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug \
...

docker-compose.yml: docker-compose.yml:

services:
  php:
    build:
      dockerfile: ${PWD}/.devcontainer/Dockerfile
    image: php-fpm
    environment:
      XDEBUG_MODE: ${XDEBUG_MODE} // off
      XDEBUG_CONFIG: ${XDEBUG_CONFIG}

xdebug info: x调试信息:

php -r 'xdebug_info();'
Version => 3.0.0
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
Feature => Enabled/Disabled
Development Aids => ✘ disabled
Coverage => ✘ disabled
GC Stats => ✘ disabled
Profiler => ✘ disabled
Step Debugger => ✘ disabled
Tracing => ✘ disabled

                                   PHP                                   
                           Build Configuration                           
Version => 7.4.11
Debug Build => no
Thread Safety => disabled
                                 Settings                                 
Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => /usr/local/etc/php/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/conf.d
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-amqp.ini,
/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini,
Directive => Local Value => Master Value

xdebug.mode => develop => develop

UPDATE:更新:

My case: I use VSCode to debug my app, so I need to turn on Xdebug module only when Xdebug listening is active.我的案例:我使用 VSCode 来调试我的应用程序,所以我只需要在 Xdebug 侦听处于活动状态时打开 Xdebug 模块。 Better way to do that is using env XDEBUG_CONFIG and XDEBUG_MODE, because it not require change ini files.更好的方法是使用 env XDEBUG_CONFIG 和 XDEBUG_MODE,因为它不需要更改 ini 文件。

It actually works.它确实有效。 I mean: the actual behaviour / final result.我的意思是:实际行为/最终结果。

Despite the fact that it shows xdebug.mode => develop the actual features are ALL turned OFF:尽管它显示xdebug.mode => develop实际功能全部关闭:

Feature => Enabled/Disabled
Development Aids => ✘ disabled
Coverage => ✘ disabled
GC Stats => ✘ disabled
Profiler => ✘ disabled
Step Debugger => ✘ disabled
Tracing => ✘ disabled

I've tested it locally on a Windows 10.. and I see the same:我已经在 Windows 10.. 本地测试了它,我看到了相同的结果:

php.ini has php.ini有

xdebug.mode = debug

Without XDEBUG_MODE override cmd shows that the debugger is enabled as it should:没有XDEBUG_MODE覆盖 cmd 显示调试器已启用,因为它应该:

Feature => Enabled/Disabled
Development Aids => ✘ disabled
Coverage => ✘ disabled
GC Stats => ✘ disabled
Profiler => ✘ disabled
Step Debugger => ✔ enabled
Tracing => ✘ disabled
...
xdebug.mode => debug => debug

With XDEBUG_MODE override:使用XDEBUG_MODE覆盖:

C:\Users\Andriy
$ SET XDEBUG_MODE=off

C:\Users\Andriy
$ php -r "xdebug_info();"

...
Feature => Enabled/Disabled
Development Aids => ✘ disabled
Coverage => ✘ disabled
GC Stats => ✘ disabled
Profiler => ✘ disabled
Step Debugger => ✘ disabled
Tracing => ✘ disabled
...
xdebug.mode => debug => debug

If I run this command (passing additional Xdebug config param that tells to start debugging straight away):如果我运行这个命令(传递额外的 Xdebug 配置参数,告诉我立即开始调试):

php -dxdebug.start_with_request=yes -r "xdebug_info();"

then WITHOUT the override it will try to establish the debug connection and WITH override it will not try to do that.然后在没有覆盖的情况下,它将尝试建立调试连接,而在有覆盖的情况下,它将不会尝试这样做。 That confirms that the override works (at very least here in my environment).这证实了覆盖有效(至少在我的环境中是这样)。

The XDEBUG_MODE environment defined in docker-compose definition is overriding the default value from Dockerfile. docker-compose 定义中定义的 XDEBUG_MODE 环境覆盖了 Dockerfile 的默认值。

Your way only works if you invoke docker-compose with the --env-file ( > docker-compose --env-file=xdebug.env... )仅当您使用--env-file ( > docker-compose --env-file=xdebug.env... ) 调用docker-compose时,您的方式才有效

I guess what you want is to inherit a XDEBUG_MODE you are defining inline or is already present in the terminal/shell environment.我想你想要的是继承你定义的内联 XDEBUG_MODE 或者已经存在于终端/shell 环境中。 In that case you just need to declare the var without any value在这种情况下,您只需要声明没有任何值的 var

services:
  php:
    environment:
      XDEBUG_MODE

and call docker-compose similar to > XDEBUG_MODE=Off docker-compose并调用docker-compose类似于> XDEBUG_MODE=Off docker-compose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM