Posts tagged with “debugging”

October 3

Howto: Xdebug installation and setup

To install Xdebug, it's easy if you've installed PHP extensions before, follows the basic 4 step procedure. Also we'll need to download it, I've been using the latest 2.0 beta with no problems, you can visit the Xdebug site to get more information and download it.

First we have to run phpize, this builds the configure script and other make/configure related files tailored to your install of PHP, you'll need your PHP install's bin folder in path, typically this is for system installed PHP or custom installs in /usr/local. If you installed PHP via something like apt in debian or ubuntu, you'll need a particular package, this should be 'php5-dev' which includes phpize and necessary files to build PHP extensions. Then we can run configure, make, then make install to install it. The basic installation commands:

$ cd xdebug-2.0.0beta6
$ phpize
$ ./configure
$ make
$ sudo make install

Now that we installed it, Xdebug requires some minimal php.ini setup, particularly a special way of loading the extension unlike normal ones. I basically want the debugger available when I need it, and for Xdebug to be using it's stack traces for any notices/errors, and profiling to be only on when I want it. Below is what I have, for debugging support (which requires something like Komodo or Eclipse with Xdebug support) you'll need to enter the address of the machine that will have a debugger, along with the port, and the username you're on on that machine. So this setup, my laptop will do any debugging, and I'm always 'jerome' on any machine, which is what the debugger clients usually use to identify the ide/client. For profiling you'll need to have a directory writable by the web server where the cachegrind formatted profiler dumps go which is the last option I have.

zend_extension= /usr/lib/php5/20051025/xdebug.so ;full path to xdebug extension, installed in your extensions folder
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=192.168.1.40
xdebug.remote_port=9001
xdebug.idekey=jerome
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = /storage/sites/profiler_files

For other options, you can consult www.xdebug.org for documentation on xdebug and it's configuration, available functions, and more.

Now to use profiling, all you have to do is restart web server if you haven't already after saving php.ini changes, and then any script you want profiled, just include XDEBUG_PROFILE=1 in GET or POST and this will cause profiling to be run and a cachegrind.out.##### type file to be generated in the path specified in php.ini. It's best to rename the file to something usable after the script is done so you know what it is, and if you do the same script, it might try to write to that same file. These files are then best viewed in a program that knows cachegrind format, like KCacheGrind as seen in my previous post.

Technorati Tags: , , , ,

10:52 PM | 0 Comments | Tags: , , , ,
September 6

Experience with Xdebug and Komodo Pro

So with the recent arrival of a MacBook Pro for work, I needed to setup my PHP development environment which usually consisted of Zend Studio, but that has YET to come out with a intel/universal release despite the fact that it's 99% java. One of the useful things with Zend Studio is that you can debug and profile PHP sites with it, which I don't actually use all that often, it's still incredibly valuable. So Zend Studio may actually run fine on here through Rosetta, but word is, not very well and installer has major issues specially with latest version. What will not work at all is Zend Platform or Zend Studio Server, comprising of ZendOptimizer and what not, PHP extensions, which will not load into apache/php at all being PPC library files.

In comes Xdebug, an open source PHP debugging and profiling extension. It also totes a few nice features beyond that, like ability to give you stack traces for just about any error message, including notices and warnings. Installation of Xdebug was easy if you're familiar with PHP extension compliation, plus if you're trying out Komodo Pro also, it can install the extension for you and set it up. Xdebug is not too useful by itself, it's best used with an IDE like Eclipse PHP IDE or Komodo, which allows you to view the PHP source file and step through it, set breakpoints, and see what variables contain what. This pretty much compares on-part with Zend Studio's debugging abilities, with the added bonus of some other cool features.

The one thing I'd love to see be easier and as nice as in Zend Studio is the profiling of PHP code in Xdebug. This can be enabled and you can flag a page for profiling easily, what this does though is dump a file to a determined folder by the php.ini. This file is a cachegrind format file which can be viewed nicely in apps like KCacheGrind or WinCacheGrind. This would be cool and all if I weren't on OS X. It doesn't seem there's any tool to view this data easily and nicely (specially as nice as a pie graph and such in Zend Studio) in OS X. This seems to be mostly due to the fact that these tools are all based around a tool called valgrind which is for linux and does not run on OS X that I can tell. What I did find after googling a bit is a perl script that will let me get some basic stats out of these files, ct_annotate.pl from the callgrind package. I found this after searching a bit on a mailing list as an attachment. My blog refuses to provide this file though.

I still haven't had too much experience with Xdebug yet, but I'm impressed so far, just wishing for a visualization tool for cachegrind formatted data in OS X. I also tried Komodo Pro during this whole process, which seems like quite the powerful IDE. I was sparked to try this while looking into Xdebug, and not having any interesting in Eclipse, and running across someone in a similar boat over at Random Strings. This person, also a certified Zend Engineer, used to use Zend Studio but made the switch to Komodo Pro after purchasing a MacBook Pro. Seemed to be pretty positive, at least about debugging. My initial experience is pretty positive, seems to be quite powerful, the newest upcoming release has some nice features like CSS auto-complete, a HTTP inspector, and also ability to debug javascript via Firefox and an extension. I'm still going to give it a run through with my trial copy to get a good feel for it. My biggest problem so far is just that Zend Studio has an incredible auto-completion ability with it's parsing of PHPdoc tags and being able to complete instance functions etc. Komodo Pro seems to be limited to class names and functions. I'll probably use Zend Studio again on the MacBook Pro soon as it's universal or available for intel, which Komodo Pro did very fast.

Check out some simple screenshots. * Komodo Pro - Editing * Komodo Pro - Debugging PHP page * Simple profiling via ct_annotate.pl

Technorati Tags: , ,

12:29 AM | 0 Comments | Tags: , , , , , ,