question:

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:

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". 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 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.

So, I never thought I would have to debug xdebug itself, but: How can I debug the xdebug to code editor connection? 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?

## Various Configuration Settings ##

I am on ubuntu linux 14.04.

Here is my xdebug.ini conf if pertinent:

[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:

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:

Answer:

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).

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).

xdebug is the most known PHP extension for debug. 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.

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. 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. xdebug doesn't kick in on all requests to the server but only when it founds a marker in the request. 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). 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. 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). 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. 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). 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. The output of telnet localhost 9988 says nobody is listening on port 9988. The xdebug client should listen there.

I never worked with Sublime Text (and its packages). This article explains how to install and make it work. However, it doesn't explain how to configure it to listen on port 9988.

I would start by setting the PHP xdebug extension to connect to the default port (9000):

xdebug.remote_port=9000

and then, if everything works, I would try to find out how to configure the Sublime Text xdebugpackage to listen on a different port. Do you really need it to listen on a different port?

What if the web server and the xdebug client are on different computers?

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. 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.

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.

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 sshsession to the remote machine.

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). This way the remote xdebug PHP extension is able to contact the remote xdebug client (assuming it is listening).

answered Aug 23 '16 at 7:39
axiac

40.7k64160
  •  
    I re-moved everything back to port 9000, but it still doesn't allow me to connect to that port. telnet localhost 9000 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused – Kzqai Aug 27 '16 at 13:19 
  •  
    I re-read your question now very carefully and something is not clear: do you have the Xdebug Client plugin installed in Sublime Text? Sublime Text needs it in order to be able to debug PHP scripts. If you have it installed then open Sublime Text and use the "Start Debugging" command from the "Tools -> Xdebug" menu. The Xdebug Client opens four tabs in Sublime Text. Open a console and run the telnet localhost 9000command. It should work. – axiac Aug 27 '16 at 17:41
  •  
    Yeah, definitely had the Xdebug client plugin installed (as the options you mention are available). After searching around this bug report: github.com/martomo/SublimeTextXdebug/issues/160 And finally getting some "Xdebug client has crashed" error messages (which did not appear at all before, possibly hardcoded against the 9000 port or something? Who knows), I think that it may be that the xdebug client crashes when using against Sublime Text 3 as opposed to Sublime Text 2. Going to report my findings & recommendations as a separate answer for others, and award bounty to you. – Kzqai Aug 29 '16 at 16:12
  • 1
    Nice info we got here :) – felipsmartins Jan 16 '17 at 15:03
  • 1
    I found the ssh tunneling a great solution – vivoconunxino Mar 14 at 10:37

php 中 拓展 xdebug的完全理解的更多相关文章

  1. PHP的学习--在Atom中使用XDebug(Mac)

    之前写过一篇博客<PHP的学习--在sublime中使用XDebug(Ubuntu)>,讲了在Ubuntu系统 sublime 中配置 XDebug,其实配置好之后,我也很少用,原因有两点 ...

  2. C#中对IDisposable接口的理解

    http://blog.sina.com.cn/s/blog_8abeac5b01019u19.html C#中对IDisposable接口的理解 本人最近接触一个项目,在这个项目里面看到很多类实现了 ...

  3. js中的回调函数的理解和使用方法

    js中的回调函数的理解和使用方法 一. 回调函数的作用 js代码会至上而下一条线执行下去,但是有时候我们需要等到一个操作结束之后再进行下一个操作,这时候就需要用到回调函数. 二. 回调函数的解释 因为 ...

  4. [BS-18] 对OC中不可变类的理解

    对OC中不可变类的理解 OC中存在很多不可变的类(如NSString,NSAttributedString,NSArray,NSDictionary,NSSet等),用它们创建的对象存在于堆内存中,但 ...

  5. oracle中 connect by prior 递归算法 -- 理解

    oracle中 connect by prior 递归算法 -- 理解 http://blog.163.com/xxciof/blog/static/7978132720095193113752/  ...

  6. MyEclipse 10.x中拓展自动提示功能

    原文转自:MyEclipse 10.7中拓展自动提示功能 在myeclipse 9以前的版本中,我们如果要为html编辑器添加自动的代码提示可以这样操作: 1.windows-->prefere ...

  7. MVC架构中的Repository模式 个人理解

    关于MVC架构中的Repository模式   个人理解:Repository是一个独立的层,介于领域层与数据映射层(数据访问层)之间.它的存在让领域层感觉不到数据访问层的存在,它提供一个类似集合的接 ...

  8. 关于MySQL中的自联结的通俗理解

    关于MySQL中的自联结的通俗理解 前言:最近在通过SQL必知必会这本书学习MySQL的基本使用,在学习中也或多或少遇到了点问题,我也正好分享给大家,我的这篇博客用到的所有表格的代码都是来自SQL必知 ...

  9. 关于Autosar中的NM模块的理解

    本篇文章主要介绍AutoSar中关于NM模块的理解. 阅读本篇文章希望达到的目的: 1. NM(网络管理)是用来做什么的: 2. AutoSar中网络管理的原理: 3.项目实例介绍 1. NM(网络管 ...

随机推荐

  1. (翻译)在 Xamarin 应用中使用 MongoDB

    原文地址:https://blog.xamarin.com/write-apps-using-mongodb-xamarin/ 在设计应用时,最重要的决定之一就是要使用什么类型的数据库. 不久之前,这 ...

  2. grunt 自定义任务实现js文件的混淆及加密

    //自定义任务 module.exports = function (grunt) { // 项目配置 var http = require('http'); var qs = require('qu ...

  3. centos7yum安装tomcat

    执行安装命令 [root@localhost ~]# yum -y install tomcat 查询tomcat是否安装成功 [root@localhost ~]# rpm -q tomcat to ...

  4. 洛谷P2168 [NOI2015] 荷马史诗 [哈夫曼树]

    题目传送门 荷马史诗 Description 追逐影子的人,自己就是影子. ——荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马 ...

  5. 洛谷P1801 黑匣子

    题目传送门 分析:这题和另外一个题目中位数非常相似,有兴趣可以先看看,比这一题简单.首先暴力模拟还是别想了,估计30%的数据都有点悬.正解应该是用二叉堆.但是如果用一个堆当然不方便,所以建两个堆,一个 ...

  6. div垂直居中的方法

    在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...

  7. VM虚拟机安装kali linux

    点击文件,新建虚拟机新建一个虚拟机 点击后出现这个,选择典型 点击下一步,然后选择安装程序光盘映像文件(iso),然后浏览,找到你下载的镜像 点击下一步,选择linux,选择最高Debian版本的,6 ...

  8. Xamarin 中Visual Studio创建项目提示错误

    Xamarin 中Visual Studio创建项目提示错误 错误信息:Object reference not set to an instance of an object 出现这种情况,是由于没 ...

  9. 【二分】【线段树】hdu6070 Dirt Ratio

    size(l,r)表示区间l,r权值的种类数,让你求min{size(l,r)/(r-l+1)}(1<=l<=r<=n). last[r]表示a[r]上一次出现的位置, 就是二分验证 ...

  10. 【动态规划/递推】BZOJ1806[IOI2007]- Miners

    IOI历史上的著名水题,我这种蒟蒻都能写的东西. [思路] 用1.2.3分别代替三种食物,0表示当前矿井没有食物.f[i][a][b][c][d]当前第i个食物,矿1的食物顺序由上至下为a,b:矿2的 ...