GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing xdebug.org — Xdebug: Documentation » Step Debugging Step DebuggingXdebug's step debugger allows you to interactively walk through your code to debug control flow and examine data structures. Introduction #Xdebug interacts with IDEs to provide step debugging functionality, and therefore you also need to configure an IDE that knows how to talk to Xdebug with the open DBGp protocol. This protocol is supported by nearly every PHP IDE (including Visual Studio Code and PhpStorm), and also by text-based editors. There is also a simple Command Line Debug Client available as part of the Xdebug project, but it is strongly recommended that you use an IDE for debugging. An overview of third party clients is available further down this page. Configuring Step Debugging #In your In set-ups where PHP/Xdebug and your IDE all run on the same host, this is all you need to configure on the PHP and Xdebug side. (Skip to Activating the Debugger if that's the case.) If PHP/Xdebug run on a different machine than your IDE, or in a Docker container, then you need to tell Xdebug where to make the debugging connection to, as it is Xdebug that initiates the communication to the IDE, and not the other way around. If PHP/Xdebug run on a different machine than your IDE in the same sub-net,
and you run your browser on the same host as your IDE, then you set the
xdebug.discover_client_host setting to Xdebug Cloud is a Proxy-as-a-Service, which can help you with complexities with regards to networking. A common use case is having multiple developers, who share a common development server on private network, while working in a remote location. In more complex set-ups you need to configure the host and port that Xdebug connects to yourself. With xdebug.client_host you can select the IP or hostname of the machine that runs your IDE, and with xdebug.client_port the TCP port. Make sure that the host running PHP/Xdebug can connect to your IDE with the configured IP address and port, and that there is no firewall or other software blocking an incoming connection. If it is not possible for Xdebug to make a direct connection to the IDE due to networking or a firewall, then you can only use the Xdebug Cloud service. This acts like a relay between Xdebug and your IDE so that you can succesfully initiate a debug session. Activating Step Debugging #In the default configuration, the debugger activates if a "trigger" is
present, although it's possible to instruct the debugger to always initiate a
debugging session by setting xdebug.start_with_request to Which trigger to use depends on whether you're debugging a PHP application through a browser, or on the command line, such as when running unit tests. Command Line #To signal the debugger to initiate connections, Xdebug will look whether the
The value of the variable does not matter unless you have set up a trigger value with xdebug.trigger_value. On Unix like platforms, you can set it like: export XDEBUG_SESSION=1 On Windows, you set the environment like: set XDEBUG_SESSION=1 When you now run a php script with Please refer to the Troubleshooting section if it does not seem like Xdebug is activating. Web Application #The recommended way to initiate a debugging session is by configuring your IDE to accept incoming debugging connections, and then use a browser extension which sets the right trigger cookie. Browser Extension Initiation #The extensions are:
Each extension adds an icon to your browser where you can select which functionality you want to trigger. Xdebug will continue to start debugging for every request as long as the debug toggle has been enabled. Manual Initiation #Alternatively, you can signal Xdebug to initiate debugging for a
single request by adding
For debugging multiple subsequent requests, Xdebug supports debugging sessions managed by a cookie. Set the Xdebug will set the Before Xdebug 3.1, the time-out of the cookie is one hour. Starting with Xdebug 3.1, the cookie has no time-out configured. If you set the HTTP Cookie #Xdebug will initiate a debug session in the presence of the
A typical header looks like: Cookie: XDEBUG_SESSION=start Alternative Ways of Triggering the Debugger #There are other ways how debugger activation can be triggered. By Calling xdebug_break()Calling xdebug_break() will trigger a debugging connection as long as
xdebug.start_with_request is set to Upon an Error SituationIf you set xdebug.start_upon_error to Ignoring a Request to Trigger the Debugger #In some situations, it might be necessary to prevent Xdebug from initiating
a debug session, even if any of the triggers (such as the
In this situation you can set Troubleshooting #You can troubleshoot Xdebug's attempts at initiating debugging connections by configuring a log file through xdebug.log. When the connection is successfully established the log will also contain the communication between Xdebug and IDE. The log file will contain to which IP addresses it is attempting to connect and at which ports, which should be a great help debugging why it sometimes doesn't work. A "remote log file" is also required when reporting a bug in Xdebug's step debugger. There are several logging levels which can be configured through xdebug.log_level. The xdebug.log setting requires as argument a full path to a file, to
which the user that PHP/Xdebug runs as can write to. It is advisable to use
something like Be aware: On many Linux distributions that run services through Systemd, the actual file path could be different, such as: /tmp/systemd-private-80b2a71a8b9843c0b7c21b0d357e59cc-apache2.service-CN4RBr/xdebug.log Debugging Clients #This is an incomplete list of third-party clients, both free and commercial. Please refer to the original authors of these tools for documentation and support:
The simple command line client Implementation Details #This section documents some implementation details, that are mostly useful for authors of debugging clients that interact with Xdebug. DBGp: context_names
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), 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 Content #
Related Settings and Functions #
Settings #string xdebug.client_discovery_header = "HTTP_X_FORWARDED_FOR,REMOTE_ADDR" #If xdebug.client_discovery_header is configured to be a non-empty string, then the
value is used as key in the For example, if xdebug.client_discovery_header is set to
It is possible to configure multiple fallbacks by using a comma separated
list of values. For example if you want to use PHP automatically prepends If you have logging enabled, and set the xdebug.log_level setting to
Xdebug 3.2 and later no longer fall back to the
string xdebug.client_host = localhost #Configures the IP address or hostname where Xdebug will attempt to connect to when initiating a debugging connection. This address should be the address of the machine where your IDE or debugging client is listening for incoming debugging connections. Xdebug also supports a few other ways of specifying the host to connect to,
but these methods are not always available. xdebug_info() shows whether
the
If xdebug.discover_client_host is enabled then Xdebug will only use the value of this setting in case Xdebug can not connect to an IDE using the information it obtained from HTTP headers. In that case, the value of this setting acts as a fallback only. This setting can additionally be configured through the
integer xdebug.client_port = 9003 #The port to which Xdebug tries to connect on the remote host. Port
This setting can additionally be configured through the
string xdebug.cloud_id = #With this setting you configure Xdebug for use with Xdebug Cloud. It needs to match one of the tokens from your profile page. Your IDE needs to be configured with the same token for Xdebug and your IDE to communicate through Xdebug Cloud. In PhpStorm you can find this setting under: integer xdebug.connect_timeout_ms = 200 #The 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. string xdebug.control_socket = "default" #Introduced in Xdebug >= 3.3 Linux and Windows only. When set to A command can currently be used to:
You should use the Xdebug Control tool to interact with this control socket. When this setting is set to
If your system (or container) does not have a reliable TSC clock, then
You can programatically check whether control sockets are enabled for your PHP
build by calling xdebug_info() with boolean xdebug.discover_client_host = false #If enabled, Xdebug will first try to connect to the client that made the
HTTP request. It checks the If xdebug.client_discovery_header is configured, then the If Xdebug can not connect to a debugging client as found in one of the HTTP headers, it will fall back to the hostname or IP address as configured by the xdebug.client_host setting. This setting does not apply for debugging through the CLI, as the
This setting can additionally be configured through the
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.client_host. string xdebug.idekey = *complex* #Controls which IDE Key Xdebug should pass on to the debugging client or proxy. The IDE Key is only important for use with the DBGp Proxy Tool, although some IDEs are incorrectly picky as to what its value is. The default is based on the If this setting is set to a non-empty string, it selects its value over
The internal IDE Key also gets updated through debugging session management and overrides the value of this setting as is explained in the Step Debugging documentation. This setting can additionally be configured through the
string xdebug.log = #Configures Xdebug's log file. Xdebug will log to this file all file creations issues, Step Debugging connection attempts, failures, and debug communication. Enable this functionality by setting the value to a absolute path. Make sure
that the system user that PHP runs at (such as The file is opened in append-mode, and will therefore not be overwritten by default. There is no concurrency protection available. The log file will include any attempt that Xdebug makes to connect to an IDE: [2693358] Log opened at 2020-09-02 07:19:09.616195 [2693358] [Step Debug] INFO: Connecting to configured address/port: localhost:9003. [2693358] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). [2693358] [Profiler] ERR: File '/foo/cachegrind.out.2693358' could not be opened. [2693358] [Profiler] WARN: /foo: No such file or directory [2693358] [Tracing] ERR: File '/foo/trace.1485761369' could not be opened. [2693358] [Tracing] WARN: /foo: No such file or directory [2693358] Log closed at 2020-09-02 07:19:09.617510 It includes the opening time ( It includes:
For Step Debugging: INFO: Connecting to configured address/port: localhost:9003. ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). For Profiling: ERR: File '/foo/cachegrind.out.2693358' could not be opened. WARN: /foo: No such file or directory For Function Trace and Flame Graphs: ERR: File '/foo/trace.1485761369' could not be opened. WARN: /foo: No such file or directory All warnings and errors are described on the Description of errors page, with
detailed instructions on how to resolve the problem, if possible. All errors are always logged through
PHP's internal logging mechanism (configured with error_log
in Step Debugger CommunicationThe debugging log can also log the communication between Xdebug and an IDE.
This communication is in XML, and starts with the <init
xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
fileuri="file:///home/httpd/www.xdebug.org/html/router.php"
language="PHP" xdebug:language_version="7.4.11-dev"
protocol_version="1.0" appid="2693358" idekey="XDEBUG_ECLIPSE">
<engine version="3.0.0-dev"><![CDATA[Xdebug]]></engine>
<author><![CDATA[Derick Rethans]]></author>
<url><![CDATA[https://xdebug.org]]></url>
<copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright>
</init>
The Beyond the <- feature_set -i 4 -n extended_properties -v 1
-> <response
xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
command="feature_set" transaction_id="4" feature="extended_properties" success="1">
</response>
<- step_into -i 9
-> <response
xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
command="step_into" transaction_id="9"
status="break" reason="ok">
<xdebug:message filename="file:///home/httpd/www.xdebug.org/html/router.php" lineno="3">
</xdebug:message>
</response>
You can read about DBGP - A common debugger protocol specification at its dedicated documation page. The xdebug.log_level setting controls how much information is logged. Many Linux distributions now use systemd, which
implements private tmp directories. This means that when PHP
is run through a web server or as PHP-FPM, the This setting can additionally be configured through the
integer xdebug.log_level = 7 #Configures which logging messages should be added to the log file. The log file is configured with the xdebug.log setting. The following levels are supported:
Criticals, errors, and warnings always show up in the diagnostics log that you can view by calling xdebug_info(). Criticals and errors are additionally logged through
PHP's internal logging mechanism (configured with error_log
in This setting can additionally be configured through the
string xdebug.mode = develop #This setting controls which Xdebug features are enabled. This setting can only be set in The following values are accepted:
You can enable multiple modes at the same time by comma separating their
identifiers as value to xdebug.mode: XDEBUG_MODE environment variableYou can also set Xdebug's mode by setting the Some web servers have a configuration option to
prevent environment variables from being propagated to PHP and Xdebug.
string xdebug.start_upon_error = default #Step Debugging can be activated when a PHP Notice or Warning is emitted, or when a Throwable (Exception/Error) is thrown, depending on the value of this setting:
This setting is independent of xdebug.start_with_request, and therefore it is
not necessary to set xdebug.start_with_request string xdebug.start_with_request = default #Step Debugging, a Function Trace, Flame Graphs, Garbage Collection Statistics, or Profiling can be activated at the start of a PHP request. Whether this happens depends on the value of this setting:
string xdebug.trigger_value = "" #This setting can be used when xdebug.start_with_request is set to
In The legacy names Normally, Xdebug does not look at which value is actually used. If this setting is set to a non-empty string, then Xdebug will only trigger if the value matches the value of this setting. With the following settings: xdebug.mode=profile xdebug.start_with_request=trigger xdebug.trigger_value=StartProfileForMe Xdebug's profiler will only start when either the environment variable
From Xdebug 3.1, it is possible to configure multiple values by using a comma separated list. In that case, Xdebug will trigger if the supplied value matches any of the entries that are configured through this setting: xdebug.trigger_value=StartDebuggerForMe,StartDebuggerForYou See also:
Functions #xdebug_break() : bool #Emits a breakpoint to the debug client This function makes the debugger break on the line it is called from, as if a normal file/line breakpoint was set on this line through the debugger protocol.
If no debugging session is active yet, and xdebug.start_with_request is set to
The function returns xdebug_connect_to_client() : bool #Instructs Xdebug to establish a debugging session Introduced in version 3.1
This functions instructs Xdebug to try to establish a connection to a debugging client. Normally, Xdebug tries to start a debugging session at the start of the request. If a debugging client is not listening at that point, then Xdebug does not try to re-establish a connection during the remainder of the request. In the situation where one long running PHP process handles multiple tasks, perhaps from a queue, calling xdebug_connect_to_client() can then be used to re-try to establish a connection for a specific worker job. xdebug_info( ?string $category = null ) : mixed #Show and retrieve diagnostic information This function presents APIs to retrieve information about Xdebug itself. Which information gets returned, or displayed, depends on which arguments, or none at all, are given.
| |||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |