Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    Debugging PHP: Eclipse PDT + XDebug + XDebug helper

    8th June 2009

    Stimulated by a bug in a complex and unfamiliar web PHP application with heaps of custom tweaks by other programmers, I decided to try a more professional approach to PHP programming and debugging than the standard var_dump() and family.

    As a result, I’m now using Eclipse PDT with Xdebug and Xdebug Helper (Firefox extension). Now I don’t understand how I used to debug my PHP programs before!

    After proper configuration (I’m using local Apache, but it is also possible to debug remotely), my work flow is rather simple:

    • use my web-app as usual, e.g. tweaking and testing here and there
    • if something server-side goes wrong: click the XDebug helper icon in Firefox, and perform some server-request action (e.g. load a page)
    • debugging is started in Eclipse PDT, where I can step through the code, set breakpoints, and examine all variables
    • as soon as the problem is fixed – click the XDebug helper icon again to continue using the site normally (w/o invoking the debugger)

    It takes some time to get used to, but then it’s a breeze.

    Some advice:

    • don’t use apt-get/aptitude to install Eclipse; it will be much easier both in the short and long run to use some all-in-one package from the Eclipse PDT site; all you need to do – download, extract, run!
    • before actually starting to do anything, tweak the eclipse.ini file by increasing heap size from 40 MiB (default) to some larger value (I used 128MiB). If you don’t do this, then at some point your debugging will become painfully sloooow, and then you’ll start getting tons of “out of heap memory” errors, each one suggesting that you quit Eclipse immediately
    • install XDebug with apt-get/aptitude – worked perfectly, and there’s /etc/php5/conf.d/xdebug.ini not to mess with php.ini
    • do read XDebug guide for PDT 2.x (I’m assuming you got the 2.x version); it should be the only document you will really need to configure everything

    I only wish Eclipse was faster – that is, written not in Java but e.g. C or C++.

    Share

    3 Responses to “Debugging PHP: Eclipse PDT + XDebug + XDebug helper”

    1. Yossi Leon Says:

      You can also use Zend Debugger and download the all-in-one package which includes WTP+DLTK+PDT+Zend Debugger Plugin for script debugging.
      If you want to debug on a web server, remotely or locally you need to install Zend Debugger extensions on the server or install Zend Server CE (FREE) which includes web server, debugger and even mysql if you need.
      Anyway, you can find all information here: http://www.zend.com/en/community/pdt

      Good luck,
      Yossi

    2. Bogdan Says:

      Thanks!

      Personally, I’ll stick to my current setup for now, but your suggestion does seem like a good alternative.

    3. Vlatko Ć urlan Says:

      You can also check out my video teaching how to use Eclipse PDT + XDebug + SSHFS to debug sites remotely. (Linux oriented of course)
      http://www.evorion.hr/fileadmin/videos_en/eclipse_php_xdebug.ogv

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>