views:

158

answers:

3

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.

+5  A: 

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.

Justin Ethier
hi and thanks, i try to read the doc first. Hopefully, it's easy to understand. Cause everything tags with debug usually too complicated.
justjoe
Agreed: especially with PHP, a lot of the articles about debugging are usually overly complicated. Anyway, read over the documentation and if you have any questions just let me know - I set this up on a Linux server so I should be able to answer questions with regard to that environment.
Justin Ethier
thanks for the support. But i use windowns on xampp as server. so, i will try to download the dll file. And maybe i will ask about how to use xdebug when the doc start to frustrated me.
justjoe
+1 for suggesting XDebug - and I can confirm that it works with Eclipse as well (including CodeIgniter with mod_rewrite - works without problems)
Henrik Opel
but you will have to disable zend-optimizer in your php.ini first. then only it will work.
Gaurav Sharma
+1  A: 

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.

shikhar
+2  A: 

Easiest option (without installing any IDE) is to use firefox FirePHP addon.

  1. Download and install FirePHP firefox addon
  2. Download FirePHP core library from their website
  3. 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
  4. Turn PHP’s output buffering on
  5. 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.
  6. See this link for how to use firephp library: http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/
Vasu