Xdebug  
  XDEBUG EXTENSION FOR PHP | DOCUMENTATION - DEBUGGER
home | updates | installation | documentation | screenshots | license | support



INTRODUCTION

Xdebug's (remote) debugger allows you to examine data structure, interactively walk through your and debug your code. There are two different protocols to communicate with the debugger: a GDB-like command protocol (GDB) which is implemented in Xdebug 1.3 and 2; and the DBGp protocol which is implemented in only Xdebug 2.

CLIENTS

A simple commandline client for the GDB protocol is bundled with Xdebug 1.3. A client implementation can also be found in the free editor WeaverSlave and in Maguma's WorkBench.

Xdebug 2 is bundled with a simple commandline client for the DBGp protocol. Another client implementation of the DBGp protocol can be found in the next version of ActiveState's Komodo.

STARTING THE DEBUGGER

In order to enable Xdebug's debugger you need to make some configuration settings in php.ini. These settings are xdebug.remote_enable to enable the debugger, xdebug.remote_host and xdebug.remote_port to configure the IP address and port where the debugger should connect to and xdebug.remote_handler to configure which debug backend to use ("gdb" or "dbgp"). If you want the debugger to initiate a session when an error situation occurs (php error or exception) then you also need to change the xdebug.remote_mode setting. Allowed values for this setting are "req" (the default) which makes the debugger initiate a session as soon as a script is started, or "jit" when a session should only be initiated on an error.

After made all those settings Xdebug will still not start a debugging session automatically when a script is run. You need to activate Xdebug's debugger and you can do that in two ways:

  1. When running the script from the command line you need to set an environment variable, like:
    export XDEBUG_CONFIG="idekey=session_name remote_enable=1"
    php myscript.html
    
    You can also configure the remote_host, remote_port, remote_mode and remote_handler in this same environment variable. All those configurable settings can also be set with normal php.ini settings.
  2. If you want to debug a script started through a web browser, simply add XDEBUG_SESSION_START=session_name as parameter to the URL. Refer to the next section to read on how debug sessions work from within a browser window.

Before you start your script you will need to tell your client that it can receive debug connections, please refer to the documentation of the specific client on how to do this. To use the bundled client simply start it after compiling and installing it. You can start it by running "debugclient". If you want to use the GDB commandset to debug your scripts, make sure you use a debugclient as bundled with Xdebug 1.3 as the one bundled with Xdebug 2 only works with the DBGp commandset.

When the debugclient starts it will show the following information and then waits until a connection is initiated by the debug server:

Xdebug Simple DBGp client (0.8.0)
Copyright 2002-2004 by Derick Rethans.
- libedit support: enabled
	 
Waiting for debug server to connect.

After a connection is made the output of the debug server is shown:

Connect
<init fileuri="file:///home/derick/foo5.html" language="PHP"
      protocol_version="1.0" appid="27010">
    <engine version="2.0.0dev">Xdebug</engine>
    <author>Derick Rethans</author>
    <url>http://xdebug.org</url>
    <copyright>Copyright (c) 2002-2004 by Derick Rethans</copyright>
</init>
(cmd)

Now you can use the commandset as explained on the GDB or DBGp documentation page. When the script ends the debug server disconnects from the client and the debugclient resumes with waiting for a new connection.

HTTP DEBUG SESSIONS

Xdebug contains functionality to keep track of a debug session when started through a browser: cookies. This works like this:

  • When the URL variable XDEBUG_SESSION_START=name is appended to an URL Xdebug emits a cookie with the name "XDEBUG_SESSION" and as value the value of the XDEBUG_SESSION_START URL parameter. The expiry of the cookie is one hour. The DBGp protocol also passes this same value to the init packet when connecting to the debugclient in the 'idekey' attribute.
  • When there is a GET (or POST) variable XDEBUG_SESSION_START or the XDEBUG_SESSION cookie is set, Xdebug will try to connect to a debugclient.
  • To stop a debug session (and to destroy the cookie) simply add the URL parameter XDEBUG_SESSION_STOP. Xdebug will then no longer try to make a connection to the debugclient.

 
RELEASES
[29-11-2004]
Source:
Debug client 0.8.0 (binary):
[15-09-2004]
Windows modules:
[30-06-2004]
Source:
Modules for 4.3.x (binary):
Debug client 0.7.0 (binary):

DEVELOPMENT VERSION (2.0dev)
Instructions to get Xdebug 2.0dev from CVS can be found here. This version compiles on PHP 4.3.0 and higher.

BINARY SNAPSHOTS (2.0dev)
Modules for 4.3.x-dev:
Modules for 5.0.x-dev:
Modules for 5.1.x-dev:

OLDER RELEASES
Source:

 
 
This site and all of its contents are Copyright © 2002, 2003, 2004 by Derick Rethans.
All rights reserved.