Debug PHP with Eclipse? - php

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.

Related

Xdebug PHP. What are the optimal settings? Mine is dead slow

It's an old-age question. Am crawling at this point. It's year 2023, and yes, I have read tons of post here and elsewhere on the internet pertaining to this issue. It's important I use Xdebug for development. It's really concerning since a job that was to take half a day is now in its fifth day.
I have these settings;
;[xdebug]
;zend_extension=xdebug
xdebug.mode=debug
xdebug.log_level=0
xdebug.client_host=127.0.0.1
xdebug.remote_connect_back=0
Using Xdebug with PhpStorm.
When Xdebug is enabled (uncommented above), pages clock at 6s-25s or more. When disabled, pages come in like a cool breeze at 800ms. Am unable to figure out what is wrong!
Why so slow? What can I do to improve speed? Thank you.
I had the same problem on an Windows 10 machine with VS-Code (Visual Studio Code) IDE and XAMPP for local Wordpress development: PHP takes 10 to 20 times longer for execution when xdebug is activated.
There is a workaround for this problem.
In php.ini configure:
xdebug.start_with_request = trigger
and in your PHP-Code use:
xdebug_break();
As a consequence of this, xdebug will start working only if it receives the signal "xdebug_break();" in your PHP code. There will be a breakpoint in the line after that. Then you can continue with step debugging etc.
As I said: I don't use PhpStorm, but Visual Studio Code as an IDE. In VS Code you need to install the PHP extension pack and then start the VS Code debugger with "Listen for xdebug".
Hopefully this will work with PhpStorm, too.

How do I get NetBeans to show visual code execution for URL with GET parameters?

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.

Netbeans start xdebug on specific page

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"

Can not make PHP PDT xDebug to stop at breakpoints in Eclipse

By choosing Break at First line, the debugger gets active when entering each file, allowing me to step in and out of the code.
But it is a bit cumbersome having to tab your way through half a million steps to get to the point where it starts to get interesting.
My setup is WIMP Window 7, PHP 5.3
; xDebug config
zend_extension = "C:\Program Files (x86)\PHP\v5.3\ext\php_xdebug-2.2.1-5.3-vc9-nts.dll"
xdebug.remote_autostart=0;
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
I have made sure that the path mapping is correct.
But could it be because i'm linking to the PHP files from my Eclipse project?
After downloading Eclipse Juno i'm able to stop at breakpoints.
I have tried everything with Eclipse Indigo.
Version: 3.7.2
Build id: M20120208-0800
Just wont work, either with an internal or external browser.
Time to move on to Juno i guess?
Eclipse has an option to turn off "break at first line". Go to "Windows -> Preferences -> PHP -> Debug" and uncheck "Break at first line" and also to go in "Run > Debug Configurations > PHP Web Application" and unselect "Break at first line" in all the configurations. Then restart Eclipse.
For all those, that are still fighting with this problem, some handy tips.
Check which version (package) of Eclipse you have? It turns out, that Helios package has some bugs and doesn't stops on breakpoints, when you debug your application as Web Application. Debugging works only, if you run it as PHP Script. Which makes it pretty useless for debugging process.
You should consider either reverting to older Galileo Package Eclipse for PHP Developers or installing newest Eclipse Juno (or even newest developer version of Eclipse Kepler), which doesn't have PDT support build in, but you can easily add it to then, using Help > Install New Software.. (point it to http://download.eclipse.org/tools/pdt/updates/release).
These versions are reported to be able to debug as Web Application, respecting breakpoints.
Also, remember, that Xdebug must be run as Zend Extension in order to support breakpoints! In other words remove extension=xdebug.so (on Linux or xdebug.dll on Windows) line from your php.ini and replace it with zend_extension=/full/path/to/xdebug.so (on Linux or zend_extension=X:\full\path\to\xdebug.dll on Windows). Zend extensions requires full path, even if they're put into /php/ext folder, as regular PHP extensions. You'll find more info on this in Xdebug FAQ (look for an answer to "Xdebug is only loaded as PHP extension and not as a Zend Extension" question).
Here is a post describing how to get breakpoints to work with XDebug in Eclipse.
http://programmersjunk.blogspot.com/2013/05/eclipse-and-xdebug.html

MacGDBp, but better?

For debugging php code I use MacGDBp but it has its quirks: it shows only the top frame variables of the stack, it sometimes refuses to display any variable at all and last version has decorates the source text with non ascii characters.
Is there any alternative that is native OS X? (ie. not Eclipse, I can't stand it).
I have also used MacGDBp and became frustrated with the limitations you mentioned. While it is not a native app per say, NetBeans 6.5 and higher is free and includes a decent PHP debugger that works with XDebug.
http://netbeans.org/kb/docs/php/debugging.html
It is not without it's own set of issues, but it does seem to be more reliable than MacGDBp.
If you are not opposed to paying, the Komodo IDE (My IDE of choice) also has a PHP debugger.
http://www.activestate.com/komodo-ide?src=AScom&type=bn&X=HP&campaign=KMD
Also, though slightly off topic, you may find the easy Xdebug FireFox extension useful:
https://addons.mozilla.org/en-US/firefox/addon/58688/
Lastly, the XDebug website has a list of additional clients, browser plugins and instructions on how to use them:
http://www.xdebug.org/docs/remote#browser_session
For Linux users - http://protoeditor.sourceforge.net/ has a nice lightweight client for Xdebug which is also available as a plugin for Kate (this is not mentioned on the Xdebug site)
Xdebug also runs happily with XAMPP - if you figure out where to put the compiled .so file ;)
There also is an article describing on how to install Xdebug on Linux w/ XAMPP on the SaniSoft blog: http://www.sanisoft.com/blog/2007/06/23/how-to-install-xdebug-php-extension-for-xampp-on-linux/
http://debuggable.com/posts/setting-up-xdebug-on-mac-os-x-or-win32-linux:480f4dd6-0240-4a90-8fa1-4e41cbdd56cb
That helped me a lot. Perhaps it helps you as well.
Edit: By the way, it is a PHP extension. It can be used in competent IDEs including Netbeans, Eclipse, AS Komodo... Oh, and you may use it manually as well by setting a special GET variable (or COOKIE) (see xdebug manual for more info).

Categories