简体   繁体   English

Xdebug 无法连接到客户端,从哪里开始调试调试器?

[英]Xdebug unable to connect to client, where do I start debugging the debugger?

I'm setting up xdebug for php within sublime text, and xdebug keeps on logging errors related to being unable to connect:我正在 sublime 文本中为 php 设置 xdebug,并且 xdebug 不断记录与无法连接相关的错误:

Log opened at 2016-08-18 21:06:01
I: Connecting to configured address/port: localhost:9988.
E: Could not connect to client. :-(
Log closed at 2016-08-18 21:06:01

I hoped that debugging directly by going to http://localhost:9988 in my browser might help, but it simply displays the google chrome error page: "localhost refused to connect".我希望通过在浏览器中直接访问http://localhost:9988进行调试可能会有所帮助,但它只会显示谷歌浏览器错误页面:“localhost 拒绝连接”。 Perhaps the error exists on the other end, that data can't be pushed to the sublime text client, I don't know.也许另一端存在错误,无法将数据推送到 sublime text 客户端,我不知道。 Sublime text xdebug does show the message "Reloading /var/log/xdebug/xdebug.log" when I run tests/etc, so it seems to be aware of the php code being run, just doesn't get any further.当我运行测试/等时,崇高的文本 xdebug 确实显示消息“正在重新加载 /var/log/xdebug/xdebug.log”,所以它似乎知道正在运行的 php 代码,只是没有进一步。

So, I never thought I would have to debug xdebug itself, but: How can I debug the xdebug to code editor connection?所以,我从没想过我必须调试 xdebug 本身,但是:如何调试 xdebug 到代码编辑器的连接? If this were nginx, I would start debugging the virtualhost, but since it's xdebug... ...I have no idea where to start debugging the lack of an app to connect to?如果这是 nginx,我会开始调试虚拟主机,但因为它是 xdebug... ...我不知道从哪里开始调试缺少要连接的应用程序?

## Various Configuration Settings ## ##各种配置设置##

I am on ubuntu linux 14.04.我在 ubuntu linux 14.04 上。

Here is my xdebug.ini conf if pertinent:如果相关,这是我的 xdebug.ini conf:

[xdebug]
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host="localhost"
xdebug.remote_handler="dbgp"
xdebug.remote_port=9988
xdebug.remote_mode = req
xdebug.overload_var_dump=0
xdebug.idekey = sublime.xdebug
xdebug.remote_log="/var/log/xdebug/xdebug.log"
;https://github.com/martomo/SublimeTextXdebug

Xdebug installed: Xdebug 安装:

apt-cache policy php-xdebug
php-xdebug:
  Installed: 2.4.0-5+donate.sury.org~trusty+1
  Candidate: 2.4.0-5+donate.sury.org~trusty+1
  Version table:
 *** 2.4.0-5+donate.sury.org~trusty+1 0
        500 http://ppa.launchpad.net/ondrej/php/ubuntu/ trusty/main amd64 Packages
        100 /var/lib/dpkg/status

Module active:模块激活:

php -m | grep -i xdebug
xdebug
Xdebug

phpinfo xdebug settings: phpinfo xdebug 设置:

通过 phpinfo 进行 xdebug 设置

PHP debugging requires two components that collaborate: a PHP extension that acts as server and a software that knows how to talk to this extension and drive its functionality (it is the client). PHP 调试需要两个协作的组件:一个充当服务器的 PHP 扩展和一个知道如何与此扩展通信并驱动其功能的软件(它是客户端)。

However, despite the usual client-server protocols where the client connects to the server, the PHP debugger works the other way around: the server is the one that connects to the client (that should be started and listening on port 9000 ).然而,尽管客户端连接到服务器的常用客户端-服务器协议,PHP 调试器的工作方式相反:服务器是连接到客户端的服务器(应该启动并侦听端口9000 )。

xdebug is the most known PHP extension for debug. xdebug是最著名的用于调试的 PHP 扩展。 There are many programs and program extensions/plugins that acts as clients for it.有许多程序和程序扩展/插件充当它的客户端。 I didn't work with Xdebug package for Sublime (I didn't work with Sublime, in the first place) but the principles are the same.我没有使用 Sublime 的 Xdebug 包(首先我没有使用 Sublime),但原理是相同的。

How a debugging session works?调试会话如何工作?

The client software (Sublime with the Xdebug package in your case) starts listening on port 9000 of localhost , waiting for the server to start the connection.客户端软件(在您的案例中带有 Xdebug 包的 Sublime)开始侦听localhost端口9000 ,等待服务器启动连接。 It probably doesn't listen on the port all the time but only when the developer tells it so.它可能不会一直监听端口,而是只有在开发人员告诉它时才会监听。

You start the PHP script to debug.您启动 PHP 脚本进行调试。 xdebug doesn't kick in on all requests to the server but only when it founds a marker in the request. xdebug不会启动对服务器的所有请求,但仅当它在请求中找到标记时才会启动。 Depending on the SAPI used to run the script, the marker is either an environment variable (for CLI scripts) or a cookie or a GET or POST argument (for web pages).根据用于运行脚本的 SAPI,标记是环境变量(对于 CLI 脚本)或 cookie 或GETPOST参数(对于网页)。 Read more on the "Starting The Debugger" section of the documentation.阅读文档的“启动调试器”部分的更多信息。

When the PHP interpreter starts the execution of the PHP script, if xdebug founds the marker explained above then it tries to connect the xdebug client.当 PHP 解释器开始执行 PHP 脚本时,如果xdebug找到了上面解释的标记,那么它会尝试连接xdebug客户端。 Otherwise, it stays out of the way and lets the script run at its full speed.否则,它会避开并让脚本全速运行。

When the debugging marker is present in the environment, the xdebug extension (the server) tries to connect to the xdebug client (by default on port 9000 of localhost but these settings can be changed as needed).当调试标记存在于环境中时, xdebug扩展(服务器)尝试连接到xdebug客户端(默认情况下在localhost端口9000 ,但可以根据需要更改这些设置)。 If it cannot connect (because the client is not listening) then it logs the failure then puts itself out of the way and lets the script run at its full speed.如果它无法连接(因为客户端未在侦听),则它会记录故障,然后将自己排除在外并让脚本全速运行。

After it successfully connects to the client, the xdebug PHP extension either stops before running the first statement of the PHP script or runs the script until its execution reaches a breakpoint.在它成功连接到客户端后, xdebug PHP 扩展要么在运行 PHP 脚本的第一条语句之前停止,要么运行脚本直到它的执行到达断点。 This behaviour and the list of breakpoints are sent by the client to the server during their initial communication as the connection was established.此行为和断点列表由客户端在建立连接时的初始通信期间发送到服务器。 Then the extension waits for commands from the client.然后扩展等待来自客户端的命令。 The client displays to the developer the current state of the running script (the next statement to run, the values of the variables in the current scope etc) and waits for commands (run next statement, continue, add/remove breakpoints, watch some variable etc).客户端向开发人员显示正在运行的脚本的当前状态(要运行的下一条语句、当前范围内变量的值等)并等待命令(运行下一条语句、继续、添加/删除断点、观察一些变量等)。

Why it doesn't work for you?为什么它不适合你?

It's not very clear for me from your question but I'll assume you run the webserver (with the PHP interpreter and the xdebug extension) on the same computer you run the xdebug client ( localhost ).从您的问题中我不是很清楚,但我假设您在运行xdebug客户端( localhost )的同一台计算机上运行网络服务器(带有 PHP 解释器和xdebug扩展)。 If this is not the case, don't despair.如果情况并非如此,请不要绝望。 The solution is a command line away (read at the end of the answer).解决方案是一个命令行(在答案末尾阅读)。

From the information you posted in the question is clear that xdebug is installed, enabled and it works properly.从您在问题中发布的信息来看,很明显xdebug已安装、启用并且可以正常工作。 The output of telnet localhost 9988 says nobody is listening on port 9988 . telnet localhost 9988的输出表示没有人在监听端口9988 The xdebug client should listen there. xdebug客户端应该在那里监听。

I never worked with Sublime Text (and its packages).我从未使用过 Sublime Text(及其包)。 This article explains how to install and make it work. 本文介绍了如何安装并使其工作。 However, it doesn't explain how to configure it to listen on port 9988 .但是,它没有解释如何配置它以侦听端口9988

I would start by setting the PHP xdebug extension to connect to the default port ( 9000 ):我首先将 PHP xdebug扩展设置为连接到默认端口 ( 9000 ):

xdebug.remote_port=9000

and then, if everything works, I would try to find out how to configure the Sublime Text xdebug package to listen on a different port.然后,如果一切正常,我会尝试找出如何配置 Sublime Text xdebug包以侦听不同的端口。 Do you really need it to listen on a different port?你真的需要它来监听不同的端口吗?

What if the web server and the xdebug client are on different computers?如果 web 服务器和xdebug客户端在不同的计算机上怎么办?

If you need to debug a PHP script that runs on a remote machine the xdebug client listens on the local machine (on port 9000 ) and the xdebug extension tries to connect to port 9000 on the remote machine.如果您需要调试在远程机器上运行的 PHP 脚本, xdebug客户端会在本地机器上侦听(在端口9000 ),而xdebug扩展会尝试连接到远程机器上的端口9000 A solution that is possible in intranets and VPNs is to configure xdebug to connect to port 9000 of the local machine but, apart from these conditions, it usually also requires changes in the firewall and/or other security software. Intranet 和 VPN 中可能的解决方案是配置xdebug以连接到本地机器的端口9000 ,但除了这些条件之外,它通常还需要更改防火墙和/或其他安全软件。

The easiest way to debug the PHP scripts in this situation if you have ssh access to the remote machine is to create a ssh tunnel from port 9000 of the remote machine to port 9000 of the local machine.调试在这种情况下,PHP脚本,如果你有最简单的方法ssh远程计算机访问是创建一个ssh从隧道端口9000的远程计算机的端口9000的本地机。

Assuming you use ssh to connect to the remote machine (to put the files on it), all you have to do is to append -R 9000:localhost:9000 to the command line you use to connect and start a ssh session to the remote machine.假设您使用ssh连接到远程机器(将文件放在上面),您所要做的就是将-R 9000:localhost:9000附加到用于连接并启动到远程的ssh会话的命令行机。

As long as this connection is open, any connection request on port 9000 (the first 9000 on the command line above) of the remote machine ( -R ) is forwarded through the tunnel to the port 9000 (the second 9000 from the command line) of the local machine ( localhost ).只要这种连接是打开的,在端口的任何连接请求9000 (第一9000的远程计算机(上面在命令行上) -R )通过隧道转发到端口9000 (第二9000从命令行)本地机器( localhost )。 This way the remote xdebug PHP extension is able to contact the remote xdebug client (assuming it is listening).这样远程xdebug PHP 扩展就能够联系远程xdebug客户端(假设它正在监听)。

Ok, so after extensive testings of different settings, here are my suggestions for debugging the problem for people who come after me:好的,在对不同设置进行了大量测试后,以下是我为追随我的人调试问题的建议:

  1. Do not rely on testing with only 1 xdebug client!不要依赖仅使用 1 个 xdebug 客户端进行测试! It's trivial to install two editors/IDEs, so get an alternate editor running to make it possible to see whether there is a problem with xdebug, or with the specific client!安装两个编辑器/IDE 是微不足道的,所以运行一个备用编辑器,以便可以查看 xdebug 或特定客户端是否有问题!

  2. There can be 3 locations that carry configuration for the xdebug+xdebug client combination! xdebug+xdebug 客户端组合的配置可以有3 个位置! The client(or editor plugin) configuration, the 20-xdebug-conf.ini file (or in php.ini equivalent), and your project-specific configuration.客户端(或编辑器插件)配置、20-xdebug-conf.ini 文件(或在 php.ini 中的等效文件)和您的项目特定配置。 Make sure all 3 locations are in sync in terms of port, path_mapping, etc.确保所有 3 个位置在端口、路径映射等方面都是同步的。

If you are using xdebug-v3 , please try:如果您使用的是xdebug-v3 ,请尝试:

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1

This should solve your issue.这应该可以解决您的问题。

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

相关问题 Xdebug: [Step Debug] 无法连接到调试客户端 - Xdebug: [Step Debug] Could not connect to debugging client Xdebug 无法连接到调试客户端。 试过:本地主机:9000 - Xdebug Could not connect to debugging client. Tried: localhost:9000 Xdebug: 无法连接到调试客户端 (Phpstorm + WSL2) - Xdebug: Could not connect to debugging client (Phpstorm + WSL2) 如何修复 Sublime Text 中的“无法启动 Xdebug 调试会话” - How to fix "Unable to start Xdebug debugging session" in Sublime Text XDebug 无法连接到客户端 - XDebug could not connect to client Xdebug:[Step Debug] 无法连接到调试客户端。 试过:localhost:9003(通过 xdebug.client_host/xdebug.client_port 回退):-( - Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-( PHP远程调试:XDebug无法连接到JetBrains的php Storm客户端 - PHP remote debugging: XDebug can't connect to JetBrains php Storm client 当我在VSCode中启动调试器来调试php文件时,没有任何调试操作? - No debugging action when I start debugger in VSCode to debug a php file? NetBeans + xdebug:每次启动调试器时如何重新启动PHP会话? - NetBeans + xdebug: How can I restart my PHP session every time I start the debugger? Netbeans,xdebug:从浏览器开始调试 - Netbeans, xdebug : start debugging from browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM