Is there a back button in the Eclipse PHP Xdebug debugging pointer? - php

I'm debugging PHP with Xdebug using Eclipse. All went OK except when I would like the debugging pointer to go back to the previous lines. Is this possible? I don't want to restart the debugging.
In details, supposing I'm on line 500 then I proceed to line 505, can the debugging pointer in Eclipse goes back to line 500 to check the state of my variables?
I'm still new to debugging with Eclipse so I appreciate any tips on how this will be done. Thank you.

No, it isn't possible. Xdebug doesn't allow you to do it.
You will have to run the program again from the start to get back to the same point. (unless it's in a loop of course)

This kind of feature is highly sophisticated and requires the debugger to store the application state at all times (starting from a breakpoint) in order to "go back in time" and re-run code.
I haven't seen this with xdebug or even PHP at all. Last time I worked with this feature was in the old C++ days with Visual Studio Debugger. Microsoft invented something they called "IntelliTrace" for this.
(see article about IntelliTrace here: http://msdn.microsoft.com/en-us/magazine/ee336126.aspx)

Related

PHP XDebug disable breaking on each request

I'm writing a webapplication that uses JS and PHP. Each time I refresh I get about 5 ajax calls to my php script. This is getting quite annoying using XDebug since it breaks on each of those request (without a breakpoint placed).
I thought this was a common problem but I can't seem to find anyting about it. Does anyone know how to disable breaking on each request?
EDIT: I'm using Wamp and Netbeans 7.0
Rob
It's the IDE the one that's stopping. In NetBeans, go to Tool-> Options-> PHP-> Debugging and uncheck Stop at first line.
(In earlier NetBeans versions the option was under Tool-> Options-> PHP-> General)
From what i remember, xdebug adds something like XDEBUG_SESS_ID=xxxxxxxx to the url when debugging. if this is the case, then remove that from the url.
What is most likely that you have some empty src="" tags or alike. You need to find out what (by checking your apache logs) which requests are made. Xdebug itself does not decide to make requests.

How to know where the script stopped?

I was wondering if there was a way to know where the script stopped (ie: file + line), which would be useful for debugging or for removing stupid 'exit' calls lost somewhere in the code.
Thanks in advance
Wrong (and I'm sorry for not testing it first): You could use register_shutdown_function in conjunction with debug_backtrace.
See here for a duplicate of your question: Fastest way to determine where PHP script exits .
If you want to remove exit from the script, try using PHP Code Sniffer PEAR package http://pear.php.net/package/PHP_CodeSniffer
Just create a sniffer to find out where all the exits are in the code (you get a report of file and line).
If you want to find out what line a script stopped at, use a debugger and you can get a stack trace to find out the last line a script executed too (Xdebug is easy to use and set up). Any debugger is going to severely hinder performance as it needs to manage more memory.
I'm not sure what IDE your using (if any), but this would be trivial using xdebug. I personally use it with netbeans and it works great although it is a bit tricky to setup. It will let you walk through your code step by step and show exactly where it is exiting.

Can anybody suggest a good Debugging package for PHP?

I use firebug and smarty so i get good debugging data from that but i'd like to see my database query times and page processing times as well.
Xdebug is very good. It works very well in combination with Netbeans IDE for PHP.
This is a great package to relay data to firebug:
http://www.firephp.org
xdebug is awesome, because it lets you step through code inspecting variables as you go.
It also lets you do profiling (dumps callgrind files into a directory of your choosing, describing in very detailed fashion what happened how many times, when, and how long everything took)
To take full advantage of xdebug, you need a good IDE, i suggest netbeans, but you can use any one of the major packages nowadays.
As linked many times by others, FirePHP and Xdebug are awesome...
But you also asked about page render times and query times.
Unless you're already using a framework that collects this data for you, you're going to need to collect it and set up reporting for it yourself.
Debugging PHP Code on Windows with Visual Studio 2008 or 2010 => http://www.jcxsoftware.com

How to do Debugging of PHP?

how we do basic debugging in PHP ?
Can anybody share true horror story on debugging PHP application (or (even better) on PHP framework such Codeigniter and Wordpress) ?
i love to hear real experience in case i have to encounter similar situation on my journey to learn PHP.
XDebug may be used to debug a PHP application. Basically you install this on your server and configure it in PHP.ini. Then on your desktop machine, you can setup Netbeans (and maybe Eclipse, but I have not tried that) to remote debug. When you are in a remote debug session you can do any of the things you typically expect: set breakpoints, step through code, etc.
One major annoyance when using CodeIgniter with mod_rewrite is that the debugger gets confused by index.php not showing up in the URL. I am not sure if this is a problem on the client side or server, and whether CI "eating" the GET portion of a URL has anything to do with it. In any case, I have worked through it by copying a 'debug.php' file to the server and starting debugging with that file - everything seems to work fine after that.
I any case, I highly recommend you get setup with XDebug at some point. You may not use it everyday, but when you need it you'll be thankful you did your homework ahead of time.
Easiest option (without installing any IDE) is to use firefox FirePHP addon.
Download and install FirePHP firefox addon
Download FirePHP core library from their website
Extract FirePHP library you downloaded in step 2 and only copy FirePHP.class.php to CodeIgniter /application/libraries/ folder, but give it a name FirePHP.php without the class part
Turn PHP’s output buffering on
Start your Firefox, click the FireBug icon on the bottom lower area, or go to menu and select tools. After you turn on (set them to enable) FireBug and FirePHP, be sure to click on the Net tab next in line to HTML, CSS, Script, DOM and set it also to enable.
See this link for how to use firephp library: http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/
There is one problem in using IDE debugers - it's bad for debuging AJAX applications. In this case you will need to use some of browser extension. For FireFox it's FirePHP, and gor Google Chrome it's Php console.
I checked out a lot of debuggers 2 years ago when I wanted to set up a debugging environment for myself in PHP. I posted a brief post on this, you can go through it http://forums.codewalkers.com/general-chat-93/which-php-ide-to-use-840352.html
Bottomline was that Nusphere's phped was the best and its debugbreak() function makes debugging a real bliss. With codeigniter also this works fine, no tweaks required if you have already enabled get variable. The only hiccup with codeigniter+phed is that, you cannot do code navigation like "right click and find declaration" for other files models.
Off late I have been checking out codelobster they have a codeigniter plugin, but I am not through with it yet.

REMOTELY Debugging PHP Using Eclipse

I'm a self-taught noobie, trying to debug PHP on my GoDaddy hosted server. Is this idea even rational, or do I need to continue to do all development locally and just continuously re-ftp upload the changes?
Is there some way that I can use eclipse to step through, and debug my php scripts that are hosted on a third party site?
Although I have only used Netbeans and XDebug for remote debugging, it should be possible to use Eclipse PDT and XDebug. See:
setting-eclipse-pdt-and-xdebug
Debugging PHP applications with xdebug
One caveat, however. To configure xdebug you will need to modify some settings in php.ini - I am not sure if this will be possible on a hosted server. If not, you would need to have a local server that you use for debugging, and would need to figure out another solution for your "production" environment. Which may not be a bad idea, actually, as it would give you a good place to test your changes without risking breaking anything on your actual site.
Also, I recommend that you look into Netbeans, if for no other reason than to experiment and see what it can do compared to Eclipse. One nice feature is that you can set it up to automatically ftp (or scp) changed files to the remote site. So you can make some code changes, click the debug button, and after waiting a moment for your files to upload you can be stepping through code on the remote site.
While there is definitely a case for remote debugging you should always be working locally and then uploading. Anything except the most minor of changes should be done locally tested then pushed to a server - sometimes production directly, sometimes a testing server...
Yes Eclipse supports remote debugging with Xdebug as well as the one from Zend Debugger check out Justin's links as well as This one for Zend Debugger. I think Zend has an all in one with pdt+deps and Zend Debugger - ofcourse you still need to set up the extension on the server (note link is for setup on windows but hte process should be similar).
Obligatory "Ewww GoDaddy" :-)
If the web server have XDebug installed, then you can do debugging with it. Searching for it in google yield a quite num of articles on how to do it.
Personally, I'm using CodeIgniter. I do debugging using FirePHP and PQP. Make a habit to write a good indented code. You might find your code have less bug, both syntax and logic, and easier to maintained in the future. Use a consistent white space, either tab or space. Use a consistent bracket style. It will save you from the headache when re-read it for bug or adding more feature later.
I have never needed to do a step by step debug in PHP, but when I do need to debug I just output strings of the variables at that point.
However, one thing that I found, but again never used, was FirePHP:
http://www.firephp.org/
As far as I'm aware, this is not possible in Eclipse, it is, however, possible in NetBeans, but as Nathan stated, I've never really needed to remote debug any of my PHP scripts.

Categories