From Lyceum
Jump to: navigation, search

XDebug Allows for Local and Remote debugging. Kcachegrind is a graphical interface to profile information generated with Valgrind.

These two tools together are a formidable force to leverage against any code you are working on to debug, analyze and profile it.

  • Remote compute, database and I/O resources may be different
  • PHP compiled differently on server, different modules
  • Database access
  • Debug and profile tools available on the server
  • It's just better this way

Install Xdebug

Install Xdebug on remote server:

With pear: (Yum install php-pear and php-devel)

pecl install xdebug
pecl config-show
pecl info xdebug
[[email protected] ~]# locate

Configure PHP

Edit /etc/php.ini

(Note for php 5.3+ beware using other declarations to load the module)

NOTE: Don't forget - restart apache after any changes!

Verify Xdebug working via phpinfo.


Don't forget - open port 9000 on both ends (configurable of course)

Check out / Rsync Code:

You need a local copy of the code. Check it out of SVN, or just rsync it with something like:

[email protected]:~/joe> rsync -rva -e ssh [email protected]:/var/www/vhosts/drupal localCopy/

Firefox extension:

Install Easy Xdebug

Or use the manual method and add this to the page to be debugged:



Configure Eclipse

  • Preferences --> PHP --> Debugger --> Installed Debugger --> XDebug --> Configure

Set "Accept Remote Sessions (jit)" to "any"

  • Preference --> General --> Web Browser

Create new PHP Project from the source code directory your created above.

Debug it!

  • If using the Easy Debug Firefox module, click the little green bug to enable, then simple refresh the webpage. This should automatically start the debugging session in Eclipse.

Or you can . . .

  • Run "Debug as.." --> PHP Web Page
  • Right click "Debug as.." --> PHP Web Page
  • Or use "Debug Configuration"

Or, start it from the site too!

Browser will launch, and send necessary session ID to debugger Eclipse Debugger should start automatically


(KDE packages: kdesdk kcachegrind)

You start and stop the collection of profile information using the same Firefox Easy Xdebug plugin, simply click the small green box to enable profile data collection. By default this is saved in the server /tmp directory named similar to: cachegrind.out.24878, this is the file you open with kcachegrind.

For non-Linux users, I'll install this on a development box. You can then SSH in and X forward this tool back to your desktop. Once you run it you can open profile files by using the KDE fish protocol. Just click on Open and for the location type:

fish:[email protected]:/tmp

Also, to view the source code in the profiler, you have to add the directory containing it in kcachegrind:

"Settings" --> "Configure Kcachegrind" -- "Annotations" and add the source folder.

Source code will be displayed with runtime data collection information next to each function. Very cool. See the crash course at:

The official Kcachegrind documentation can be found on the projects site, and here is a PDF.

The information this provides is brilliant, not that you can display the function stack with various visual tools - check out the call graph and caller map tabs near the bottom.

See the above link and the manual (under help menu) for a good introduction.


Additional Resources:

Sample php.ini

;XDebug Settings


;PHP Profiling
;Must be writable by Web server / PHP user.
;Hint: if using suPHP this could be the owner of the script.