Poll success, but error: Operation now in progress (29). when Xdebug trying connect to PhpStorm from docker container
Poll success, but error: Operation now in progress (29). when Xdebug trying connect to PhpStorm from docker container
我正在尝试调试 CLI 脚本,但 Xdebug 无法连接到 PhpStorm。
我在 Xdebug 远程日志中看到错误 Operation now in progress (29).
。
我确定 Xdebug 配置正确,但我不知道如何调试 PhpStorm。
生成的 phpinfo() 摘要
Tailored Installation Instructions
Summary
Xdebug installed: 2.6.1
Server API: Command Line Interface
Windows: no
Zend Server: no
PHP Version: 7.1.24
Zend API nr: 320160303
PHP API nr: 20160303
Debug Build: no
Thread Safe Build: no
OPcache Loaded: no
Configuration File Path: /usr/local/etc/php
Configuration File: /usr/local/etc/php/php.ini
Extensions directory: /usr/local/lib/php/extensions/no-debug-non-zts-20160303
You're already running the latest Xdebug version
Xdebug 日志
Log opened at 2019-02-19 11:59:37
I: Connecting to configured address/port: 46.201.50.194:9000.
W: Creating socket for '46.201.50.194:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2019-02-19 11:59:37
Xdebug 配置
xdebug
xdebug support => enabled
Version => 2.6.1
IDE Key => PHPSTORM
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.extended_info => On => On
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 => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
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 => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => 127.0.0.1 => localhost
xdebug.remote_log => /app/xdebug.log => no value
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 => /tmp => /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 无法连接到 PhpStorm,因为我的外部主机 IP 无法访问 PhpStorm。
我如何调试它。
首先,我从 docker 容器中检查了 PhpStorm 监听端口(在我的例子中是 9000)
nc -vz external_ip 9000
得到了(tcp) failed: Connection refused
我从主机上尝试了同样的操作,但也收到了错误
然后我尝试从主机
nc -vz localhost 9000
我得到了[tcp/*] succeeded!
所以 xdebug.remote_host 中的问题可能不在 PhpStorm 中
我在容器中找到主机 ip
netstat -nr | grep '^0\.0\.0\.0' | awk '{print }'
将其放入 xdebug.remote_host,现在可以正常工作了
感谢@LazyOne
在我的例子中,我简单地设置了以下 xdebug conf:
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
host.docker.internal
应该'magically' 找到主机的 IP(参见 documentation)。请注意,这需要 Docker v18.03+,目前仅适用于 Mac 和 Windows 主机。
可能是您的 xdebug.remote_port 9000 正在被 php-fpm 使用。您尝试更改其他端口。示例 xdebug.remote_port=9001 并且在 launch.json 文件中仍然是 port=9000
如果有人不想硬编码或修改他们的 docker、Dockerfile 或组合文件(也许有人正在使用 2.x xdebug,它不支持环境变量)。在浏览器上使用header修改扩展添加headerX-Forwarded-For设置$_SERVER['HTTP_X_FORWARDED_FOR'] 是一种非常方便的方法。不要忘记配置xdebug.remote_connect_back=1.
Docker 文件
FROM php:7.1-apache
RUN yes | pecl install xdebug-2.5.5 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
xdebug.log
Log opened at 2021-07-06 16:06:59
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.17.0.1:9000.
W: Creating socket for '172.17.0.1:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2021-07-06 16:06:59
Log opened at 2021-07-06 16:07:40
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Remote address found, connecting to 172.30.112.1:9000.
I: Connected to client. :-)
对我来说,修复此错误只需在 PhpStorm 中单击 phone 图标两次以禁用然后重新启用侦听调试连接。
它不应该改变任何东西,但它起作用了,因为在此之前我修复了一堆其他问题,其中一个是端口 9003 被其他东西阻止了。显然 PhpStorm 在无法使用指定端口时不会发出警告,因此在解决其他问题后可能需要重新启动侦听调试连接。
我打开了“Windows Defender Firewall with Advanced Security”(Windows 防火墙设置)并发现我有两条规则,从哪里看不清楚,它们阻止了 phpStorm。
我禁用了它们 - xDebugger 开始为我工作。
你在PHP->Server配置了phpstorm的映射,你必须将项目文件映射到服务器的绝对路径eg。源 -> “/var/www/html/test/src”
还有来自服务器的包含 ip 地址的 xdebug 文件
我正在尝试调试 CLI 脚本,但 Xdebug 无法连接到 PhpStorm。
我在 Xdebug 远程日志中看到错误 Operation now in progress (29).
。
我确定 Xdebug 配置正确,但我不知道如何调试 PhpStorm。
Tailored Installation Instructions
Summary
Xdebug installed: 2.6.1
Server API: Command Line Interface
Windows: no
Zend Server: no
PHP Version: 7.1.24
Zend API nr: 320160303
PHP API nr: 20160303
Debug Build: no
Thread Safe Build: no
OPcache Loaded: no
Configuration File Path: /usr/local/etc/php
Configuration File: /usr/local/etc/php/php.ini
Extensions directory: /usr/local/lib/php/extensions/no-debug-non-zts-20160303
You're already running the latest Xdebug version
Xdebug 日志
Log opened at 2019-02-19 11:59:37
I: Connecting to configured address/port: 46.201.50.194:9000.
W: Creating socket for '46.201.50.194:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2019-02-19 11:59:37
Xdebug 配置
xdebug
xdebug support => enabled
Version => 2.6.1
IDE Key => PHPSTORM
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.extended_info => On => On
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 => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
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 => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => 127.0.0.1 => localhost
xdebug.remote_log => /app/xdebug.log => no value
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 => /tmp => /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 无法连接到 PhpStorm,因为我的外部主机 IP 无法访问 PhpStorm。 我如何调试它。 首先,我从 docker 容器中检查了 PhpStorm 监听端口(在我的例子中是 9000)
nc -vz external_ip 9000
得到了(tcp) failed: Connection refused
我从主机上尝试了同样的操作,但也收到了错误
然后我尝试从主机
nc -vz localhost 9000
我得到了[tcp/*] succeeded!
所以 xdebug.remote_host 中的问题可能不在 PhpStorm 中
我在容器中找到主机 ip
netstat -nr | grep '^0\.0\.0\.0' | awk '{print }'
将其放入 xdebug.remote_host,现在可以正常工作了
感谢@LazyOne
在我的例子中,我简单地设置了以下 xdebug conf:
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
host.docker.internal
应该'magically' 找到主机的 IP(参见 documentation)。请注意,这需要 Docker v18.03+,目前仅适用于 Mac 和 Windows 主机。
可能是您的 xdebug.remote_port 9000 正在被 php-fpm 使用。您尝试更改其他端口。示例 xdebug.remote_port=9001 并且在 launch.json 文件中仍然是 port=9000
如果有人不想硬编码或修改他们的 docker、Dockerfile 或组合文件(也许有人正在使用 2.x xdebug,它不支持环境变量)。在浏览器上使用header修改扩展添加headerX-Forwarded-For设置$_SERVER['HTTP_X_FORWARDED_FOR'] 是一种非常方便的方法。不要忘记配置xdebug.remote_connect_back=1.
Docker 文件
FROM php:7.1-apache
RUN yes | pecl install xdebug-2.5.5 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
xdebug.log
Log opened at 2021-07-06 16:06:59
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.17.0.1:9000.
W: Creating socket for '172.17.0.1:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2021-07-06 16:06:59
Log opened at 2021-07-06 16:07:40
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Remote address found, connecting to 172.30.112.1:9000.
I: Connected to client. :-)
对我来说,修复此错误只需在 PhpStorm 中单击 phone 图标两次以禁用然后重新启用侦听调试连接。
它不应该改变任何东西,但它起作用了,因为在此之前我修复了一堆其他问题,其中一个是端口 9003 被其他东西阻止了。显然 PhpStorm 在无法使用指定端口时不会发出警告,因此在解决其他问题后可能需要重新启动侦听调试连接。
我打开了“Windows Defender Firewall with Advanced Security”(Windows 防火墙设置)并发现我有两条规则,从哪里看不清楚,它们阻止了 phpStorm。
我禁用了它们 - xDebugger 开始为我工作。
你在PHP->Server配置了phpstorm的映射,你必须将项目文件映射到服务器的绝对路径eg。源 -> “/var/www/html/test/src”
还有来自服务器的包含 ip 地址的 xdebug 文件