【问题标题】:PhpStorm and Xdebug configurationPhpStorm 和 Xdebug 配置
【发布时间】:2021-08-28 08:55:25
【问题描述】:

我在使用 Xdebug 运行测试时遇到问题。 Xdebug 不会停止到断点,在我尝试 PHPStorm 后,它会在左侧下角显示“连接未建立,无法使用 'Xdebug 2.8.1' 启动调试器会话”

关于我的环境的一些信息:

  • PHP 7.4.20(我从自制软件安装了这个版本)
  • Xdebug 2.8.1

在我的phpinfo中:

Runtime:       PHP 7.4.20 with Xdebug 2.8.1
Scan this dir for additional .ini files => /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed => /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/xdebug.ini

PHP API => 20190902
PHP Extension => 20190902
Zend Extension => 320190902
Zend Extension Build => API320190902,NTS
PHP Extension Build => API20190902,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => enabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => available, disabled

Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk

This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.20, Copyright (c), by Zend Technologies
    with Xdebug v2.8.1, Copyright (c) 2002-2019, by Derick Rethans

这是我在 phpinfo 中找到的 xdebug 会话

xdebug

xdebug support => enabled
Version => 2.8.1
IDE Key => bpalumbo
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support

Supported protocols
DBGp - Common DeBuGger Protocol

Directive => Local Value => Master Value
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
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 => Off => Off
xdebug.gc_stats_output_dir => /var/tmp/ => /var/tmp/
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => no value => no value
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /var/tmp/ => /var/tmp/
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => On => On
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => /usr/local/Cellar/php@7.4/7.4.20/bin/xdebug.log => /usr/local/Cellar/php@7.4/7.4.20/bin/xdebug.log
xdebug.remote_log_level => 7 => 7
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_timeout => 200 => 200
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 => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /var/tmp/ => /var/tmp/
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

这里是 xdebug 日志

[5468] Log opened at 2021-06-11 14:26:14
[5468] I: Checking remote connect back address.
[5468] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[5468] I: Checking header 'REMOTE_ADDR'.
[5468] W: Remote address not found, connecting to configured address/port: 127.0.0.1:9000. :-|
[5468] I: Connected to client. :-)
[5468] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///Users/bpalumbo/workspace/commercetools-php-sdk/vendor/phpunit/phpunit/phpunit" language="PHP" xdebug:language_version="7.4.0" protocol_version="1.0" appid="5468" idekey="18793"><engine version="2.8.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>

[5468] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[5468] Log closed at 2021-06-11 14:26:15

如果我在这里运行/usr/local/Cellar/php@7.4/7.4.20/bin phpize 会说(我不知道它是否已连接):

Cannot find config.m4.
Make sure that you run '/usr/local/opt/php@7.4/bin/phpize' in the top level source directory of the module

在我的php.ini 中,我没有添加任何有关 Xdebug 配置的内容,但我可以在其中找到 xdebug.ini

zend_extension=xdebug.so

我错过了什么?

【问题讨论】:

  • I guess it's connected to the thing that says Debug Build =&gt; no 不相关。这只是关于 PHP 是否被编译成“调试”模式,这是 PHP 的创建者使用的。
  • 我不知道你在这里问什么。 Xdebug 已加载,它显示在 phpinfo() 输出中。你想做什么?
  • @Derick Xdebug 不会停止到断点,它说在我尝试 PHPStorm 后,在左下角“连接未建立无法使用 'Xdebug 2.8.1' 启动调试器会话”
  • @Edea_Barby 这是一个非常宽泛的“不起作用”声明,没有详细信息。 1) 显示您的实时 Xdebug 设置(phpinfo() 输出的整个 Xdebug 部分) 2) 启用 Xdebug 日志并尝试调试 - 然后查看它有什么(如果它尝试连接(如果有的话)以及响应是什么)。 3) 更好地升级到 Xdebug 3——在那里进行故障排除更容易一些。 4) 检查下面的链接。

标签: php phpstorm xdebug


【解决方案1】:

根据您的 Xdebug 日志,您需要将 Xdebug 端口从默认的 9000 更改为其他数字(例如 9003 - 在 Xdebug 3 中默认使用)。在 PHP(我猜你的情况是 xdebug.ini)和 PhpStorm 中都这样做。

在您的计算机上,TCP 9000 端口似乎已被 php-fpm 使用(默认情况下它也使用该端口 + 在这种情况下您可以看到的典型响应)或其他一些服务知道 Xdebug 协议。

Homebrew 意味着 Mac,对吗? PhpStorm 在检测 Mac 上已使用的端口时存在问题(因此 IDE 没有警告:在 Windows 和 Linux 上,您会在这种情况下看到警告)。您可以使用netstat 或类似程序(例如,Mac 上的sudo lsof -nP -iTCP -sTCP:LISTEN)检查哪个进程使用该端口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 2013-09-02
    • 1970-01-01
    相关资源
    最近更新 更多