How to debug PHP application using Eclipse PDT (xdebug and zend debugger) - php

I'm working on one application.
I am using Eclipse php Helios IDE for developing php application.
I wanted to know below things related to this IDE, so that i can implement PHP application instantly as well as very efficiently :
1) How to do remote debugging using Eclipse PHP Helios IDE
2) What is the pros and cons of xdebug and zend debugger
3) Which debugger should we use from xdebug, zend debugger.
4) Is there any other debugger available apart from above two mentioned.
Below links i refered for above mentioned debugger.
1) http://devzone.zend.com/article/2930-Debugging-PHP-applications-with-xdebug
2) http://www.eclipse.org/pdt/documents/XDebugGuideForPDT2.0.pdf
3) http://www.xdebug.org/
I am not getting exact information in above URL's,
as I mentioned specific query above those are needed.
Is anyone know any reference, please suggest me.
Thanks !!
-Pravin

I use the Galileo release, rather than the later Helios release, but I suspect they're very similar in this regard...
The answers to your questions would fill quite a reasonable chapter in a book, so instead I'll point you towards some excellent links on the topics;
2) This article is a great post on the pro's and con's of each with Eclipse; Eclipse debugging with Xdebug and Zend Debugger comparison. Personally I always use xdebug since it has additional features I like, and as I don't use Zend I am not interested in any integration benefits it may offer.
3 + 1) However, there's nothing to stop you installing both and switching between them using different "server setup" configurations inside Eclipse. This post shows you how to set them up on different ports to allow this; Debugging PHP using Eclipse and PDT
There is a small catch (to either debuggers) in that if you use apache mod_rewrite (or similar) for pretty URLs, you have to be really careful to ensure the rule still passes the debug parameter as a GET value in the URL. I'm not personally aware of any way around this (e.g. via cookies).
4) Not that I'm aware of under Eclipse.
Happy reading....

Step by step Debug process using XDebug and Eclipse Helios . Hope it helps.

Related

Is it possible to Debug with Phalcon PHP?

Is it possible to debug Phalcon PHP?
I'm using Sublime 3 editor but am willing to use any editor if debugging is possible.
I found a similar question on Stack Overflow but the only answer was a sales pitch about how great Phalcon is.
Updated: I'm updating this question after the fact. I learned that debugging a Phalcon application is no different than debugging a PHP application except that you cannot debug the actual Phalcon code. I didn't think it was possible to debug at all so my question might have been misleading to other developers that were new to both PHP and Phalcon at the same time.
Unfortunately, since Phalcon is a compiled PHP extension, it's not possible to debug it using a PHP debugger. What we usually do to understand Phalcon internals is having a look at the Zephir source code.
Edit: since my original answer above could be misunderstood. I figured the question's goal was to debug Phalcons internal functions, which is only possible with a C debugger (as described in Luke's answer). Of course it is still possible to debug your own PHP code, but you may not step into Phalcon classes/methods.
I'm assuming that you want to debug your PHP code, not Phalcon extension. If you mean debugging Phalcon framework itself you should install Zephir for code modifying and use gdb to run php command (at least on linux, not sure what about other systems).
Standard var_dump(), echo, printf and die
It works well with all the phalcon objects, just print out variables you want to debug using var_dump() (or other output functions) and use die() before execution your view code. If view part of application get executed will most likely replace your debug printings.
Alternatively you can also pass your variables to view part of your application and just simply use <?php var_dump($variable)?> or if you're using volt just {{dump(variable)}}.
Using XDebug Remote
This is the way I personally like the most. Yes, XDebug Remote works great with Phalcon. Personally I use NetBeans but you can use other IDE's as well. There are many tutorials for configuring all the popular IDEs so I'm not going to write it again. Note that Phalcon team suggests to use XDebug 2.2.3 or greater for better compatibility.
how to configure XDebug on PHP Storm
how to configure XDebug on NetBeans
how to configure XDebug on Sublime 3
You can read more about debuging Phalcon in Phalcon's Documentation
The best way to debug Phalcon based application is to include below code snippet into the bootstrap section of your application AND once you get any error (application level) then you'll get very useful information like below.
Backtrace
Request
Server
Includes Files
Memory (this is very useful)
(new Phalcon\Debug)->listen();

Debugging PHP in Dreamweaver CS5

is there an extension for dreamweaver cs5 that can support debugging?
I know there are other IDE's like netbeans that can accomplish that task, but I also do html/js and netbeans isn't particularly good for that.
I beg to differ. Those IDEs are, in fact, way better at anything regarding HTML/CSS/JavaScript.
I strongly recommend Zend Studio ($299) or Eclipse PDT (free). NetBeans is supposed to be an excellent IDE as well (just that I'm not familiar with it).
Also, I use Firebug to debug my JavaScripts. It's amazing. Actually, many modern browsers come equipped with JavaScript debugging tools, surprisingly including Internet Explorer (I think only version 8 and above but IE7 might have it too...I don't remember).
I highly recommend Aptana Studio http://aptana.com/
I am using it for along long time and it helped me alot
also use google chrome debugger by clicking F12 it is the best html/js debugger
I recommend you to use TSW WebCoder
In TSW WebCoder go to the Debug menu and select Setup debugging. You will be presented with a wizard, which will walk you though the entire process of setting up debugging on your machine.

Remote Debugging and Memory Profiling in PHP

Two Questions
How can I debug PHP code remotely which is lying on the server, currently I am using var_dump's to check the value of variables ?
How can I see how much memory and how much time particular function is taking to execute remotely which is lying on the server, any suggestion for good profiler for this ?
Note: I am talking about code which is lying remotely on the Server.
Like others said, Xdebug is your best bet. I'll just chime in here and mention a couple profilers. If you're on Linux you can't go wrong with KCacheGrind and on Windows it appears WinCacheGrind is what you'd use. I was not aware of remote profiling being an option, it dumps to a file which you'd need to have access to. Although, it appears you are accustomed to that already.
Komodo is a pretty nice IDE with Xdebug support (debug requires paid version), although there is no reason to not just install Eclipse and pick up the Zend PDT.
My suggestion, program in Python and be a happier developer (more developer-friendly modules/tools) :P
I think Xdebug is what you're looking for. If you don't mind spending the money, Zend IDE for Eclipse comes with Zend Debugger and it works quite well also.
As bender said: XHProf [1]: http://pecl.php.net/package/xhprof [2]: http://mirror.facebook.net/facebook/xhprof/doc.html is much lighter then XDebug and I prefer it for taking profiling info about the live site. Facebook uses it for profiling their live servers. It has nice features like aggregating the profiles and making diffs between them so you can see the regression in your code as well. If you need step by step debugger then XDebug is your call. Just be aware that XDebug on live site turned on by default imposes important degradation of performance, and output cachegrind files that site generate could fill the disk very fast.
I suggest not using XDebug on live site and if needed configuring it to activate on demand through trigger as described in docs http://xdebug.org/docs/
Configure your server to allow XDebug remote debugging and pick a client, although it can be a bit involved to set it up. I've personally used Geben for emacs as a front end for XDebug, but there are many choices.
As far as you're allowed to install stuff on the server Xdebug is the way to go for both debugging and profiling.
If you are on a shared server forget about it (unless you are a good friend of the server admin). Your best chance seems to be FirePHP - for debugging only. You may want to take a look at dBug too; it's basically a prettied up var_dump, but your eyes will be grateful for it.

How to debug a PHP application?

Which is the best way to debug an PHP application as we can debug ASP.NET application with Visual Studio ?
I'm using the IDE Eclipse PDT, which can use the PHP extension Xdebug to provide debugging functionnalities, kind of the same way as Visual Studio (a bit less powerful, maybe), which gives you the ability to do things like :
step by step
step in / out of functions / methods
see the content of variables
have a stack trace showing where you are
That's really nice to debug big programs -- especially ones you didn't write, to understand how they work (or don't ^^ )
It can also use the extension "zend debugger" ; but I've never tried this one.
Even without using a debugger like the one provided by PDT, Xdebug is a nice extension to have on a development server : it gives nice stack traces when there's an error/exception, it allows you to get nice-looking var_dump's output, ...
It can also be used to get profiling data, which you can visualize with tools like KCacheGrind, WinCacheGrind, or Webgrind.
But note it is hurting performance badly, so it definitly should not be installed on a production server !
PHP Console is good if you want to debug WEB 2.0 (AJAX) web-projects.
PHPEd is great for this, but you have to pay for it.
xdebug works, but you have to install it on the server. I haven't used it, but it seems to have a good reputation.
Some IDEs (Aptana/Eclipse + PHP springs to mind) then can interface with xdebug.
XDebug with Eclipse PDT is the best I've seen. Here is a tutorial on setting this up:
http://devzone.zend.com/article/2930-Debugging-PHP-applications-with-xdebug
NetBeans also has debug capabilities. From the website:
You can debug scripts and web pages, either locally or remotely. The NetBeans PHP debugger integration allows you to map server paths to local paths to enable remote debugging.
I use the Zend debugger and after trouble getting it working (it was a remote setup with he server and the development machine both virtual!) - it made a huge difference to my development efficiency. If you are converting from Visual Studio you will find quite a few things different and even difficult. It is worth sticking with it and mastering howewever - I can now set breakpoints in arbitary pages and navigate to them just like the user, stop and examine locals etc and then step through what happens - put simply now I can find bugs whereas without it I was guessing. Also see Developing with PHP and Eclipse (Galileo) which I found helpful.
PHP storm is a good one from JetBrains.

Step Debugger for PHP other than Zend Debugger

I just wanted to see if anyone is aware of any other debuggers capable of stepping through code.
I am aware of xdebug and use it as well as Zend Debugger and other debugging scripts (i've written my own widgets for this already).
However I am looking for a good replacement for step debugging - I've searched and searched but have yet to find anything. Is there anything else out there that can handle this? Surely Zend Debugger isn't our only solution?
I use php_dbg for my PHP step-debugging (comes with PhpED).

Categories