I have been programming PHP for quite some time but have never used an IDE or debugger to assist with this process. I decided to try and learn Netbeans with XDebug for PHP code assistance. Setting things up in the ini files was easy enough and I can verify that it is working. However, when I start the debugger in Netbeans it loads the index page of my site and the page I actually want to debug is 5 pages deep and can take a long time to navigate to with the debugger on.
I have installed the Xdebug helper for Chrome but the debugger gets suspended in Netbeans and never debugs anything on the page. Here are the steps I tried with the Xdebug helper. Note: I already set breakpoints in Netbeans.
Navigate to the page I want to debug.
Turn on Debug in Xdebug helper.
Reload page.
Here is the screenshot showing that the debugger appeared to start but suspended and stopped functioning I think.
So, I am looking for a bit of guidance and support figuring out if I may be using the tool wrong or if there is a better way to use it. Is there a way to activate it for a specific page and keep it running to debug ajax requests to php on the same page/project?
System Info
Windows 10
Wamp with PHP 5.6
Chrome, newest version
Using Moodle as a base and customing it.
Netbeans 8.1
Edit
Here is my php.ini information.
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_name=cachegrind.out.%s.%t
xdebug.profiler_output_dir="C:/WampDeveloper/Temp/xdebug"
xdebug.trace_output_dir="C:/WampDeveloper/Temp/xdebug"
Related
How do I get NetBeans to show visual code execution for URL with GET parameters?
In NetBeans I am using Xdebug with a remote server. That is working fine.
The problem is Xdebug with NetBeans only works when debugging files that don't contain GET parameters.
Basically if my file is called index.php, and I go to website.com/index.php?XDEBUG_SESSION_START=netbeans-debug It works.
If I go to website.com/index.php?test=1&XDEBUG_SESSION_START=netbeans-debug or website.com/index.php?XDEBUG_SESSION_START=netbeans-debug&test=1 it runs Xdebug, but I can't step through the code visually with NetBeans.
It seems NetBeans doesn't realize that index.php with GET parameters and no GET parameters is a the same file, and thus doesn't show me visually as I step through the code with the debug buttons.
How do I fix this?
Using:
Apache NetBeans 12.6
PHP 7.2
Xdebug 2.8.0
Windows 10
PHP.INI settings for Xdebug (I am using SSH tunnel hence why my IP is 127.0.0.1):
zend_extension=xdebug.so
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.idekey=netbeans-debug
xdebug.mode=develop,coverage,debug,gcstats,profile,trace
xdebug.remote_log="xdebug_remote_log.txt"
Thanks!
P.S: I can't use VSCode, or PHPStorm as I am using Namecheap shared hosting, so both those tools don't work.
Apache Netbeans 12.6, PHP 7.2, Xdebug 2.8.0, Windows 10
You need to upgrade, Xdebug 2 and PHP 7.2, are no longer supported.
Your settings also don't make sense, as you mix Xdebug 3 settings (xdebug.mode) with Xdebug 2 settings (the others).
To get back to your question: using GET/POST parameters to start a debugging session is pretty much deprecated. Instead, you can use a browser extension to trigger debugging requests, while your IDE listens for incoming debugging requests. Unfortunately, this is not something that Netbeans supports. Please don't use Netbeans for debugging, as it is so far behind other IDEs such as VS Code and PhpStorm.
I know there are countless of questions regarding this subject, however no matter what I've tried I've had no luck whatsoever. The problem I'm encountering is regarding breakpoints when using NetBeans and XDebug (on Windows 8.1 if that affects anything).
The issue is that no breakpoints are working. By default when debugging with NetBeans, it stops on the first line and this does successfully happen. Therefore NetBeans is somehow connecting to XDebug. However, any other breakpoints in any other files are not working.
I've tried various different settings in the php.ini file but no luck so far. I've also tried switching on the XDebug log file so that maybe I can analyse what's going on, but this also didn't work. Finally I've tried setting breakpoints using xdebug_break() which also didn't work.
XDebug settings in php.ini
;[XDebug]
; Only Zend OR (!) XDebug
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=true
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=1
xdebug.profiler_output_dir="C:\xampp\tmp"
Project Run Configuration on NetBeans
I've already looked at the following:
http://articlebin.michaelmilette.com/making-xdebug-work-with-netbeans-on-windows/
Xdebug ignores breakpoints
http://wiki.netbeans.org/HowToConfigureXDebug#Tips_from_the_NetBeans_Forums
Also note that this was working 3 days ago, however today no breakpoints are working.
Additional Info
I've run the following command in cmd php -v and the following warning was shown:
Warning: Module 'xdebug' already loaded in Unknown on line 0
Does this mean that xdebug is trying to be loaded twice? If so I'm not sure how this can be solved
Figured out what the problem was. I know that this answer will be very specific, however it might help someone in the future.
So while inspecting the code I noticed that someone added code that cleared all cookies when the login page loaded. Once the cookies are removed XDebug didn't work. The reason is that for XDebug to work it sets a cookie with the session id for example 'netbeans-xdebug' which is sent with every request on the website.
It's a very simple issue but it took nearly 2 days to find out what was going on. Once again I know that this is a very specific case but maybe it might help someone out there.
Happy coding!
I was able to successfully install both Zend as well as Xdebugger. Verified by Phpinfo as well as Eclipse verifies the Zend debug successfully installed. Although whenever I run debug from eclipse for
Xdebug it hangs at 57%`
and for Zend debugger
the browser keeps processing/busy but nothing happens
Unsure what is causing this
-> Firewall issues?
-> No Selinux in Mac so not sure if it is a permissions issue
Any clues would be helpful.
Thank you.
it seems like a miss configuration of debug. I will try to help you showing my working configurations.
This is my php.ini piece for xdebug.
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable=On
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9060
xdebug.remote_handler="dbgp"
xdebug.remote_autostart=On
It is important to note about the parameter debug.remote_host. If your client side is not allowed here, you will stuck on 57%. The value here is the IP of the machine where you are running eclipse. If you are running apache/php and eclipse in the same machine the localhost IP should work.
Adapt zend_extension parameter to your world.
Other reason you can stop in 57% is the web site is not running. Apache/PHP only will send xdebug metadata if the site is running. If you got an internal error, for example, you will be stuck on 57% also. Eclipse stops on 57% waiting for a xdebug session. You must be sure apache/php started a debug session.
Make sure the Debug configuration on eclipse is using the correct PHP server. If you are trying to run eclipse in an invalid PHP server or a PHP server which is not well configured you will stop on 57% also. So review the PHP server parameters on Debug Configurations.
Other important review you have to made is about the Xdebug configuration for eclipse. The port Debug port field must be filled with the same value of parameter xdebug.remote_port. If they are different you will be stuck in 57% also.
Please, let me know if it was helpful.
For Xdebug, this is likely a misconfigured path mapping in Eclipse. There are 10s of questions related to that here on stackoverflow and 100s of hits on google. Please check there first.
I have been trying to set up debugging using XDebug in Eclipse for the last few hours without success.
I have the following in my etc/php5/apache2/php.ini file
[XDebug]
xdebug.remote_enable=on
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=off
zend_extension = /usr/lib/php5/20090626+lfs/xdebug.so
The zend_extensions = /usr/lib...... was given to me by the custom installation instructions on the XDebug site. I followed the setup instructions exactly as they are on that page - http://xdebug.org/wizard.php
But from what I have read typing the command php -m should show XDebug twice, once under PHP modules and once under Zend modules. Well it is showing up under neither for me. So it seems that XDebug is not getting loaded at all?
Anyone any ideas on how to fix this problem and get XDebug working?
You've editted /etc/php5/apache2/php.ini file which is for apache. You'd want to edit /etc/php5/cli/php.ini for the command line interface's options.
If you pass in the phpinfo() from a web site, that PHP has run through Apache of course. And then the wizard will give you settings for the Apache set-up. If you would have passed the phpinfo() output (php -i) from the command line, it would have given you the settings for the CLI.
Something similar happened to me, the first time I setup xdebug in Eclipse it worked just fine, but the next time I tried it, it wasn't stopping at breakpoints. After a lot of research it turned out that I had 2 Eclipse instances running (one for Java and another for Php) and that caused some kind of issues with the debugger.
After closing both instances and starting Eclipse with php workspace first and then Eclipse with java workspace, xdebug worked fine again. My only idea is that debug port was already used when I tried to use it; or something like that.
An other common problem is that you use a router to get through INTERNET and that you had to forward XDEBUG PORT (generaly 9000) on your PC to make XDEBUG working with ECLIPSE.
But your router gives a dynamic IP to your PC and one day your mobile phone connects to the router before your PC and gets the IP address you configuredon you router IP FORWARDING !
The solution getting a static IP from your router. Here is an explanation: http://webologix.com/fr/blog/xdebug-eclipse-fonctionnement-aleatoire.html
What is the best way to debug PHP with Eclipse? Specifically, I'm trying to work through some issues on a Drupal 6 installation.
I like Eclipse's debugging for Java. Is there a way to do the same for PHP?
I've never used Eclipse to develop in JAVA, but if you are asking about a graphical debugger that allows to set up breakpoints, go through the current stack trace, see content of variables, and all that, there is (at least one) a solution:
You can use the Xdebug extension, and Eclipse PDT as IDE : the second one is able to use the first one as debugger, and provides an interface for it -- kind of what you might expect if you have used a visual debugger in other languages/IDE.
I've used this combination a couple of times with Drupal, to see what was executed, in which order, how, and all that (not easy to get "by hand", with the hooks mecanism), and it definitly works pretty well.
There are tutorials available on the net that explain how to setup both of those to get the debugger working. For instance :
How To Setup a Free PHP Debugger using Eclipse PDT + XDebug
Setting up Eclipse to Debug Drupal with XDebug (unfortunatly, the screenshots are missing)
Or (in french, but with screenshots ; so, might be helpful evn if not easy to understand) :
DĂ©bugger avec WampServer, Xdebug et PDT
Configurer Xdebug pour Eclipse PDT en utilisant un serveur de test distant
And here is a screenshot of what it can look like (here, I've set a breakpoint somewhere is the backoffice of Dotclear) :
(source: pascal-martin.fr)
(In theory, clicking on the image should get you to a bigger version)
The icons on top of the windows will allow you to do stuff like :
step by step
step in / out of functions / methods
And you can also
see the content of variables (top right of the screenshot)
have a stack trace showing where you are (top left of the screen shot)
of course, see were you are in the code (bottom)
I've also heard that Eclipse PDT can use the Zend Debugger extension instead of Xdebug ; but I've never tried this one.
You Can add this code in php.in file for enabling debugger.
[XDebug]
zend_extension = "D:\opt\lampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_mode=req
If you're not using the PDT for whatever reason, you could use CodeMix as a lightweight alternative to debug PHP in Eclipse. You still would need XDebug installed, of course - see this doc for more details.