Waiting For Connection (netbeans-xdebug) MAMP OS X

2019-03-16 00:37发布

Preamble

After many hours, I have been unable to get NetBeans to connect to xdebug. Some months ago, after upgrading from an old version of MAMP to MAMP PRO, debugging worked flawlessly. A week ago it started getting flakey. It would appear to connect but would not stop at the breakpoints. Restarting NetBeans (v7.0.1) and apache sometimes got it working for a short time.

I really needed it fixed so I installed the latest version of MAMP PRO (2.1.2). Now I get the Waiting For Connection message forever.

Testing I have done

While the Waiting For Connection message is there with the moving bar, I look to see if it’s listening. It is...

# lsof -i -n -P |grep 9001
java  6496  tim  230u  IPv6 0xffffff80239d8190      0t0    TCP *:9001 (LISTEN)

In NetBeans php config I have the interpreter set to: /Applications/MAMP/bin/php/php5.4.10/bin/php

Executing the following:

# /Applications/MAMP/bin/php/php5.4.10/bin/php -i | grep xdebug

tells me that xdebug is running as does phpinfo()

I have (many times) confirmed that I have the port number the same everywhere. I have tried port 9000 and 9001.

Doing a tail on xdebug.log then initiating a session from the browser without starting a debug session in NetBeans produces:

I: Connecting to configured address/port: localhost:9001.
E: Could not connect to client. :-(

With the waiting for connection message and initiating a session from the browser, I get this in the log:

: Connecting to configured address/port: localhost:9001.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///Users/tim/MAMPSites/facts.tvd.us/htdocs/sendfile/tim.php" language="PHP" protocol_version="1.0" appid="7279" idekey="netbeans-xdebug"><engine version="2.2.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2012 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

My php.ini file has the following:

[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.3.20/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9001
xdebug.idekey="netbeans-xdebug"

Update

I just noticed that the lsof command above shows NetBeans listening on ipV6. Forcing java (NetBeans) to use ipV4 does not help.

launchctl setenv JAVA_TOOL_OPTIONS -Djava.net.preferIPv4Stack=true

I found a post that suggested a test to confirm xdebug is working correctly. Create a php file:

<?php
$address = '127.0.0.1';
$port = 9000;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Unable to bind');
socket_listen($sock);
$client = socket_accept($sock);
echo "connection established: $client";
socket_close($client);
socket_close($sock);
?>

Run it from the command line and load any page in your browser with the following at the end of the url:

?XDEBUG_SESSION_START=nb

If it outputs something like "connection established: Resource id #5", xdebug is working correctly. With that, I reinstalled Java and NetBeans. I told NetBeans NOT to import my existing preferences... Still no connection.

Update2

I installed the phpStorm IDE for Mac. I learned enough about it to get the debugger running with my existing MAMP and xdebug setup. I think this confirms the problem is with NetBeans.

At this point, getting this working seems impossible. :(

4条回答
Fickle 薄情
2楼-- · 2019-03-16 01:02

I asked the same thing and got this quite good answer: How to track execution time of each line / block of lines / methods in PHP?, beside that i have this answer also on a currently running other question with the same content.

Some additional notes on that (stuff i've collected in other SO posts in my own research with this problem):

  1. The port might be also 9001 (seems to work for some people while 9000 don't).
  2. Switching to PHPStorm IDE is a real alternative that solves this problem (as PHPStorm has included perfectly running xdebug already).
  3. Download a new version of xdebug via the wizard (http://xdebug.org/wizard.php) and if you follow the instructions maybe you will be lucky.
  4. Switching off the firewall might help.
  5. Add to php.ini: xdebug.idekey=netbeans-xdebug.
  6. Find out if you have a xdebug.ini file and add the xdebug related php.ini lines to that file.
  7. you have to un-comment the zend_extension line (i.e. remove the ; at its begninning), so Xdebug is actually loaded.
  8. make sure Xdebug is loaded, calling phpinfo() from a PHP file (just to be sure).
查看更多
爷的心禁止访问
3楼-- · 2019-03-16 01:10

On clean download and install of netbeans working on xampp, xdebug worked except would not stop at breakpoints. Changed php.ini to: xdebug.remote_enable = 1 (from 0) and xdebug worked as expected!

查看更多
▲ chillily
4楼-- · 2019-03-16 01:14

Xdebug will only connect if there is an index.php file in your project folder, so check to make sure you have one.

查看更多
\"骚年 ilove
5楼-- · 2019-03-16 01:17

it works for me now. I have LAMP installed. I modified according to all answers from above, started apache2 and now it flies... i am happy... for some time i thought to switch to phpstorm, but I reconsidered... tweak a little more... et voila. it's working.

Here what I have in php.ini

zend_extension = /usr/lib/php5/20121212/xdebug.so

xdebug.max_nesting_level = 250
xdebug.auto_trace=On
xdebug.remote_enable=On
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_log="/var/log/xdebug.log"
xdebug.trace_output_dir=/var/www/AMRO
xdebug.idekey="netbeans-xdebug"
查看更多
登录 后发表回答