我想试一试Xdebug 3.0.0RC1来探索什么已经改变了,以及它带来的新特性。我还使用了最新的PhpStorm 2020.3 EAP,它支持Xdebug 3,不需要任何主要配置。下面是调试器的PhpStorm配置:
下面是我为Xdebug3尝试过的配置:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal # here I tried several combinations like: "localhost", "127.0.0.1", "172.17.0.1"
xdebug.client_port=9001 # here I tried several ports 9003 included with no success
我也尝试过完全不添加client_host/client_port
设置,但仍然失败。
我得到了这个错误:
Script php bin/console doctrine:cache:clear-metadata returned with error code 255
!! [17-Nov-2020 15:24:40 UTC] Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9001 (through xdebug.client_host/xdebug.client_port) :-(
!! [17-Nov-2020 15:24:41 UTC] PHP Fatal error: Method class@anonymous::__toString() must not throw an exception, caught Symfony\Component\DependencyInjection\Exception\AutowiringFailedException: in /var/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php on line 233
关于我的环境的一些信息:
这很奇怪(因为我正在使用的Docker版本“不支持”host.docker.internal
,但它仍然有效),同时也奇怪的是,即使调试器一直在监听传入的连接,以下的配置也适用于Xdebug 2:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000
我在这里错过了什么?
注意:我已经应用了Xdebug 这里提供的解决方案。
发布于 2020-12-18 10:26:20
PHP 7.4
Docker
PHPStorm 2020.1
X调试3.1.0
使用Dockerfile在停靠器容器中安装Xdebug
RUN pecl install xdebug-3.0.1 && docker-php-ext-enable xdebug
用以下方式配置php.ini:
[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = 1
转到PHPStorm - Settings -PHPStorm Xdebug并将端口设置为9003 (默认情况下)
就这样(:
如果您只想在需要时启用/禁用调试器:只需安装一个名为"Xdebug助手“的浏览器扩展,选择"Debug”并从php.ini中删除“php.ini= yes”
[xdebug]
xdebug.mode = debug
xdebug.discover_client_host = 1
发布于 2021-09-11 11:51:32
对我起作用的是把start_with_request
从yes改为trigger
。
这对我起了作用:
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_port=9003
编辑:如注释中所指出的,trigger/9003
是默认设置。如果此答案对您有效,则意味着某些内容正在覆盖默认设置,并且通过显式使用trigger/9003
,您将强制返回到默认设置。
发布于 2021-08-28 00:10:15
我创建了一个非常简单的配置,允许我在任何PHP版本中使用Xdebug
(v2: 5.6-7.1,v3: 7.2-8.x)。我所需要做的就是在三个地方配置PhpStorm和docker-compose.yml
,我可以进行调试。
配置:
zend_extension=xdebug.so
; https://2.xdebug.org/docs/all_settings
; ------------------------------------
; Enables Step Debugging
xdebug.remote_enable=1
; ------------------------------------
; Address where IDE listening for incoming debugging connections
xdebug.remote_host=host.docker.internal
; ------------------------------------
; Port where IDE listening for incoming debugging connections
xdebug.remote_port=9003
; ------------------------------------
; Color var_dumps when in CLI
xdebug.cli_color=1
; ------------------------------------
zend_extension=xdebug.so
; https://xdebug.org/docs/all_settings
; ------------------------------------
; Enables Step Debugging
xdebug.mode=debug,develop
; ------------------------------------
; Address where IDE listening for incoming debugging connections
xdebug.client_host=host.docker.internal
; ------------------------------------
; Port where IDE listening for incoming debugging connections
xdebug.client_port=9003
; ------------------------------------
; Color var_dumps when in CLI
xdebug.cli_color=1
; ------------------------------------
version: '3.7'
services:
#...
dev74:
hostname: 'dev-74'
container_name: 'dev_74'
image: 'gander/dev:7.4'
volumes:
- './app/xdebug3:/www/localhost'
working_dir: '/www/localhost/public'
ports:
- '8074:80'
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
PHP_IDE_CONFIG: "serverName=dev.74"
#...
通过CLI运行:
XDEBUG_SESSION=1 XDEBUG_CONFIG=1 php script.php
或者:
docker-compose exec dev74 bash -c 'XDEBUG_SESSION=1 XDEBUG_CONFIG=1 php index.php'
边注:
这个serverName
PHP_IDE_CONFIG: "serverName=dev.74"
这是PhpStorm PHP服务器的名称(如下面的屏幕快照所示)
截图:
以下是各种浏览器的扩展列表:浏览器调试扩展
https://stackoverflow.com/questions/64878376
复制相似问题