![]() |
||
Documentation
If Xdebug saves you time, please consider supporting the project.
Ā» Feature: Remote Debugging Xdebug provides an interface for debugger clients that interact with running PHP scripts. This section explains how to set-up PHP and Xdebug to allow this, and introduces a few clients. IntroductionXdebug's (remote) debugger allows you to examine data structure, interactively walk through your and debug your code. The protocol that is being used is open, and is called DBGp. This protocol is implemented in Xdebug 2, and replaces an older GDB-like protocol that is no longer supported. ClientsXdebug 2 is bundled with a simple command line client for the DBGp protocol. There are a few other client implementations (both free and commercial) as well. I am not the author of any of those, so please refer to the original authors for support:
A simple command line client for debugging is bundled with Xdebug in the
Starting The DebuggerIn 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. There is also a xdebug.remote_connect_back setting that can be used if your development server is shared with multiple developers. 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 three ways:
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". 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.10.0) Copyright 2002-2007 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
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1"
xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
fileuri="file:///home/httpd/www.xdebug.org/html/docs/index.php"
language="PHP"
protocol_version="1.0"
appid="13202"
idekey="derick">
<engine version="2.0.0RC4-dev"><![CDATA[Xdebug]]></engine>
<author><![CDATA[Derick Rethans]]></author>
<url><![CDATA[http://xdebug.org]]></url>
<copyright><![CDATA[Copyright (c) 2002-2007 by Derick Rethans]]></copyright>
</init>
(cmd)
Now you can use the commandset as explained on the DBGp documentation page. When the script ends the debug server disconnects from the client and the debugclient resumes with waiting for a new connection. Communication Set-upWith a static IP/single developerWith remote debugging, Xdebug embedded in PHP acts like the client, and the IDE as the server. The following animation shows how the communication channel is set-up:
With an unknown IP/multiple developersIf xdebug.remote_connect_back is used, the set-up is slightly different:
HTTP Debug SessionsXdebug contains functionality to keep track of a debug session when started through a browser: cookies. This works like this:
Multiple Users DebuggingXdebug only allows you to specify one IP address to connect to with xdebug.remote_host) while doing remote debugging. It does not automatically connect back to the IP address of the machine the browser runs on, unless you use xdebug.remote_connect_back.
If all of your developers work on different projects on the same (development)
server, you can make the xdebug.remote_host setting for each directory
through Apache's .htaccess functionality by using There are two solutions to this. First of all, you can use a DBGp proxy. For an overview on how to use this proxy, please refer to the article at Debugging with multiple users. You can download the proxy on ActiveState's web site as part of the python remote debugging package. There is some more documentation in the Komodo FAQ. Secondly you can use the xdebug.remote_connect_back setting that was introduced in Xdebug 2.1. Implementation Details
Xdebug's implementation of the
DBGp protocol's Custom DBGp commands
The DBGp protocol allows for debugger engine specific commands, prefixed with
the DBGp: xcmd_profiler_name_getIf Xdebug's profiler is currently active (See: Profiling PHP Scripts), this command returns the name of the file that is being used to write the profiling information to. DBGp: xcmd_get_executable_lines
This command returns which lines in an active stack frame can have a working
breakpoint. These are the lines which have an The command returns the information in the following XML format: <?xml version="1.0" encoding="iso-8859-1"?> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="xcmd_get_executable_lines" transaction_id="10"> <xdebug:lines> <xdebug:line lineno="2"></xdebug:line> <xdebug:line lineno="3"></xdebug:line> <xdebug:line lineno="4"></xdebug:line> <xdebug:line lineno="6"></xdebug:line> <xdebug:line lineno="8"></xdebug:line> </xdebug:lines> </response> Related Settingsxdebug.extended_info
Type: integer,
Default value: 1Controls whether Xdebug should enforce 'extended_info' mode for the PHP
parser; this allows Xdebug to do file/line breakpoints with the remote
debugger. When tracing or profiling scripts you generally want to turn off this
option as PHP's generated oparrays will increase with about a third of the size
slowing down your scripts. This setting can not be set in your scripts with
ini_set(), but only in php.ini.
xdebug.idekey
Type: string,
Default value: *complex*Controls which IDE Key Xdebug should pass on to the DBGp debugger handler.
The default is based on environment settings. First the environment setting
DBGP_IDEKEY is consulted, then USER and as last USERNAME. The default is set
to the first environment variable that is found. If none could be found the
setting has as default ''. If this setting is set, it always overrides
the environment variables.
xdebug.remote_addr_header
Type: string,
Default value: "", Introduced in Xdebug >= 2.4If xdebug.remote_addr_header is configured to be a non-empty string, then
the value is used as key in the $SERVER superglobal array to determine which
header to use to find the IP address or hostname to use for 'connecting back
to'. This setting is only used in combination with xdebug.remote_connect_back
and is otherwise ignored.
xdebug.remote_autostart
Type: boolean,
Default value: 0Normally you need to use a specific HTTP GET/POST variable to start
remote debugging (see Remote Debugging). When
this setting is set to 1, Xdebug will always attempt to start a remote
debugging session and try to connect to a client, even if the GET/POST/COOKIE
variable was not present.
xdebug.remote_connect_back
Type: boolean,
Default value: 0, Introduced in Xdebug >= 2.1If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request. It checks the $_SERVER['HTTP_X_FORWARDED_FOR'] and $_SERVER['REMOTE_ADDR'] variables to find out which IP address to use. If xdebug.remote_addr_header is configured, then the $SERVER variable with the configured name will be checked before the $_SERVER['HTTP_X_FORWARDED_FOR'] and $_SERVER['REMOTE_ADDR'] variables. This setting does not apply for debugging through the CLI, as the $SERVER header variables are not available there. Please note that there is no filter available, and anybody who can connect to the webserver will then be able to start a debugging session, even if their address does not match xdebug.remote_host. xdebug.remote_cookie_expire_time
Type: integer,
Default value: 3600, Introduced in Xdebug >= 2.1This setting can be used to increase (or decrease) the time that the
remote debugging session stays alive via the session cookie.
xdebug.remote_enable
Type: boolean,
Default value: 0This switch controls whether Xdebug should try to contact a debug client
which is listening on the host and port as set with the settings
xdebug.remote_host and
xdebug.remote_port. If a connection can not be established the script will just
continue as if this setting was 0.
xdebug.remote_handler
Type: string,
Default value: dbgpCan be either 'php3' which selects the old PHP 3 style debugger output, 'gdb' which enables the GDB like debugger interface or 'dbgp' - the debugger protocol. The DBGp protocol is the only supported protocol. Note: Xdebug 2.1 and later only support 'dbgp' as protocol. xdebug.remote_host
Type: string,
Default value: localhostSelects the host where the debug client is running, you can either use a host name, IP address, or 'unix:///path/to/sock' for a Unix domain socket. This setting is ignored if xdebug.remote_connect_back is enabled. Support for Unix domain sockets was introduced in Xdebug 2.6. xdebug.remote_log
Type: string,
Default value: If set to a value, it is used as filename to a file to which all remote
debugger communications are logged. The file is always opened in append-mode,
and will therefore not be overwritten by default. There is no concurrency
protection available. The format of the file looks something like:
Log opened at 2007-05-27 14:28:15 -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/x ... ight></init> <- step_into -i 1 -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/db ... ></response> xdebug.remote_mode
Type: string,
Default value: reqSelects when a debug connection is initiated. This setting can have two different values:
xdebug.remote_port
Type: integer,
Default value: 9000The port to which Xdebug tries to connect on the remote host. Port
9000 is the default for both the client and the bundled debugclient.
As many clients use this port number, it is best to leave this setting
unchanged.
xdebug.remote_timeout
Type: integer,
Default value: 200, Introduced in Xdebug >= 2.6The amount of time in milliseconds that Xdebug will wait for on an IDE to acknowledge an incoming debugging connection. The default value of 200 ms should in most cases be enough. In case you often get dropped debugging requests, perhaps because you have a high latency network, or a development box far away from your IDE, or have a slow firewall, then you can should increase this value. Please note that increasing this value might mean that your requests seem to 'hang' in case Xdebug tries to establish a connection, but your IDE is not listening. Related Functionsbool xdebug_break()
Emits a breakpoint to the debug client.
This function makes the debugger break on the specific line as if a normal file/line breakpoint was set on this line. bool xdebug_is_debugger_active()
Returns whether a debugging session is active
Introduced in version 2.6
Returns |
||
|
This site and all of its contents are
Copyright © 2002-2019 by Derick Rethans.
All rights reserved. |