Home > English, OSS Solutions > Improving PHP debug speed with XDebug 2.1

Improving PHP debug speed with XDebug 2.1

Thomas Koch published a nice comment on the XDebug mailing-list recently. It’s about using XDebug 2.1 in a different way to improve your debugging speed by allowing you to automatically open a code editor on XDebug reports.

For the sake of remembering this trick and making is more easily available, I’ve decided to publish it here:


The yet unreleased 2.1 version of XDebug has a nice new feature. The setting


allows you, to provide a printf like format for a link under the filename of
an error message.

So here comes a quick walkthrough on how to open the file from the error
message in (G)VIM:
First we need to tell the browser, in my case firefox, that the link is no web
link, but should be threaten special. We do this with the introduction of the
new protocol “vim://”.

Put this setting in your PHP configuration:


Now instruct firefox which program handles the protocol. Therefor you need to
open the about:config page and add two settings:

network.protocol-handler.external.vim boolean true
network.protocol-handler.app.vim string

The ff_xdebug_gvim file is a script that parses the link and calls gvim with
the appropriate parameters:

#!/usr/bin/env php5
// cut the vim:// prefix from the input.
$input = substr( $argv[1], 6 );

// split the filename from the line number, separted by ‘@’
// filenames could come in urlencoded
$delimiterpos = strrpos( $input, ‘@’ );
$file = urldecode( substr( $input, 0, $delimiterpos ) );
$line = ( string )( int )substr( $input, $delimiterpos – strlen( $input ) + 1 );

// –remote-silent opens an already running gvim session or creates a new one.
// Replace gvim with
// vim if you like!
system( ‘gvim –remote-silent +’.escapeshellarg( $line ).’ ‘.escapeshellarg( $file ) );

That’s it. Thanks for your patience.

And as usually: Restart your webserver and chmod +x the script.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: