0

我的新工作场所有一个奇怪的设置,它的工作原理是这样的:如果我运行 PhpStorm 并打开“开始侦听 PHP 调试连接”,那么我的本地 PHP 应用程序可以正常工作。一旦我完全关闭 PhpStorm(并因此停止侦听 PHP 调试连接),我的网页就没有加载(一分钟后 nginx 超时)。

这是我的 xdebug.ini 配置:

xdebug.mode=debug 
xdebug.start_with_request=no 
xdebug.discover_client_host=no
xdebug.client_host=127.0.0.1 
xdebug.log_level=0 
;xdebug.log=/var/log/xdebug.log

这是输出php -i | grep -i xdebug

/etc/php/7.4/cli/conf.d/20-xdebug.ini,
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
xdebug
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
             Enabled Features (through 'xdebug.mode' setting)
xdebug.auto_trace => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.cli_color => 0 => 0
xdebug.client_discovery_header => no value => no value
xdebug.client_host => 127.0.0.1 => 127.0.0.1
xdebug.client_port => 9003 => 9003
xdebug.cloud_id => no value => no value
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.collect_params => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.collect_return => Off => Off
xdebug.collect_vars => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.connect_timeout_ms => 200 => 200
xdebug.coverage_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.default_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.discover_client_host => Off => Off
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.gc_stats_output_dir => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => no value => no value
xdebug.log => no value => no value
xdebug.log_level => 0 => 0
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.mode => debug => debug
xdebug.output_dir => /tmp => /tmp
xdebug.overload_var_dump => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_enable_trigger => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_enable_trigger_value => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_output_dir => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_connect_back => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_host => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_log => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_log_level => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_mode => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_port => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_timeout => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.start_upon_error => default => default
xdebug.start_with_request => no => no
xdebug.trace_enable_trigger => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.trace_enable_trigger_value => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.trigger_value => no value => no value
xdebug.use_compression => 0 => 0
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

有趣的是,我什至尝试完全卸载 Xdebug,但我仍然遇到同样的问题(虽然我不确定我是否正确地这样做了)。

无论如何我阻止Xdebug建立连接?(并在我实际上只需要调试时启用它)

我正在使用 PHP 7.4.25、Xdebug v3.1.1,并在 Windows (Ubuntu 20.04) 上的 WSL 下运行它。我也在 nginx v1.21.4 后面运行所有东西。

更新 1: 正如@LazyOne 所问,这是我的 xdebug_info() 输出:

xdebug_info 输出的屏幕截图

xdebug_info 的第二部分

更新 2

这是 /etc/php/7.4/fpm/conf.d/xdebug.ini 的输出:

[xdebug]
xdebug.mode=debug
xdebug.start_with_request=no
xdebug.discover_client_host=no
xdebug.client_host=127.0.0.1
xdebug.log_level=0
xdebug.connect_timeout_ms=0
;xdebug.log=/var/log/xdebug.log
#zend_extension=xdebug.so
#xdebug.mode=debug
#xdebug.start_with_request=yes
#xdebug.start_upon_error=yes
#xdebug.discover_client_host=yes
#xdebug.client_host=10.0.10.1
#xdebug.client_port=9000
#xdebug.log_level=0
#xdebug.log=/var/log/xdebug.log
#xdebug.profiler_enable=1
#xdebug.remote_enable=1
#xdebug.remote_handler=dbgp
#xdebug.remote_mode=req
#xdebug.remote_autostart=1
#xdebug.remote_connect_back=1
#xdebug.idekey=PHPSTORM
#xdebug.show_exception_trace

这也是我的 /etc/php/7.4/fpm/conf.d/20-xdebug.ini

[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=no
xdebug.discover_client_host=no
xdebug.client_host=127.0.0.1
xdebug.log_level=10
xdebug.remote_autostart = 0
xdebug.log=/tmp/xdebug/xdebug.log
xdebug.connect_timeout_ms=0

这是输出grep -Ri xdebug /etc/php/7.4/fpm/conf.d/

root@DESKTOP-UB3H2M6:/var/www# grep -Ri xdebug /etc/php/7.4/fpm/conf.d/
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:[xdebug]
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:zend_extension=xdebug.so
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.mode=debug
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.start_with_request=no
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.discover_client_host=no
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.client_host=127.0.0.1
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.log_level=10
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.remote_autostart = 0
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.log=/tmp/xdebug/xdebug.log
/etc/php/7.4/fpm/conf.d/20-xdebug.ini:xdebug.connect_timeout_ms=0
/etc/php/7.4/fpm/conf.d/xdebug.ini:[xdebug]
/etc/php/7.4/fpm/conf.d/xdebug.ini:xdebug.mode=debug
/etc/php/7.4/fpm/conf.d/xdebug.ini:xdebug.start_with_request=no
/etc/php/7.4/fpm/conf.d/xdebug.ini:xdebug.discover_client_host=no
/etc/php/7.4/fpm/conf.d/xdebug.ini:xdebug.client_host=127.0.0.1
/etc/php/7.4/fpm/conf.d/xdebug.ini:xdebug.log_level=0
/etc/php/7.4/fpm/conf.d/xdebug.ini:xdebug.connect_timeout_ms=0
/etc/php/7.4/fpm/conf.d/xdebug.ini:;xdebug.log=/var/log/xdebug.log
/etc/php/7.4/fpm/conf.d/xdebug.ini:#zend_extension=xdebug.so
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.mode=debug
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.start_with_request=yes
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.start_upon_error=yes
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.discover_client_host=yes
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.client_host=10.0.10.1
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.client_port=9000
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.log_level=0
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.log=/var/log/xdebug.log
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.profiler_enable=1
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.remote_enable=1
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.remote_handler=dbgp
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.remote_mode=req
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.remote_autostart=1
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.remote_connect_back=1
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.idekey=PHPSTORM
/etc/php/7.4/fpm/conf.d/xdebug.ini:#xdebug.show_exception_trace
4

2 回答 2

2

无论如何我阻止xdebug听?

不,因为监听的不是 Xdebug。与 PhpStorm 建立连接的是 Xdebug,它可以监听传入的调试连接。

有可能由于某种原因,Xdebug 仍然尝试连接到 IDE,即使它没有在监听。连接时 Xdebug 端通常有 200 毫秒的超时,但我看到一些网络设置阻碍了这一点。

为了找出 Xdebug 是否仍在做某事以及是否仍在做某事,请创建一个日志文件,将您的更改xdebug.ini为包含以下内容,然后重新启动 Apache:

xdebug.log_level=10 
xdebug.log=/var/log/xdebug.log

日志文件将详细显示 Xdebug 是否仍在尝试连接(因为您设置xdebug.log_level为 10)。

于 2021-11-17T10:02:06.060 回答
0

首先我在 xdebug 向导的帮助下安装了 xdebug,然后我像这样配置文件:

在我的情况下是:/etc/php/7.4/cli/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host="your local ip address of the machine" for me was 192.168.68.102
xdebug.remote_connect_back=On
xdebug.client_port="9003"
xdebug.remote_handler=dbgp
xdebug.start_with_request=yes
xdebug.remote_log=/tmp/xdebug.log

然后在 phpstorm 中我配置了 PHP-> 服务器的映射:例如“src”->“/var/www/src”,你必须对所有要调试的文件夹进行配置。

最后我像这样配置了 Cli 解释器: php 的 bin 和远程主机

于 2021-11-23T16:01:03.207 回答