Xdebug provides interfaces for interaction between clients and PHP scripts. This chapter describes how to enable this feature for PHP and Xdebug, and describes some common clients.
Overview
The Xdebug (remote) debugger allows you to test the data structure, step by step, and debug your code. Xdebug provides two protocols for interaction: the old one in Xdebug1.3 and 2GDB protocol
And implemented in Xdebug2DBGp protocol
.
Client
Xdebug2 provides a simple command line-based client for the DBGp protocol. Of course, there are also some other client implementations (free and commercial ). I am not the author of these clients, so please go to the author's website for help.
- Dev-PHP (IDE: Windows)
- Eclipse plugin, which has been submitted as an enhancement for the PDT (IDE ).
- Emacs plugin (Editor Plugin ).
- ActiveState's Komodo (IDE: Windows, Linux, Mac; Commercial ).
- MacGDBP-Standalone Mac client.
- NetBeans (IDE: Windows, Linux, Mac OS X and Solaris.
- Notepad ++ plugin (Editor: Windows ).
- WaterProof's PHPEdit (IDE, from version 2.10: Windows; Commercial ).
- Anchor System's Peggy (IDE: Windows, Japanese; Commercial ).
- MP Software's phpDesigner (IDE: Windows, Commercial ).
- PHPEclipse (Editor Plugin ).
- JetBrain 'sphpstorm (IDE; inclucial ).
- Protoeditor (Editor: Linux ).
- TsWebeditor (Editor: Windows ).
- Xored's TrueStudio IDE (IDE; trusted CIAL ).
- VIM plugin (Tutorial) (Editor Plugin ).
- Jcx software's VS. Php (MS Visual Studio Plugin; Commercial ).
- XDebugClient-Standalone Windows client.
Xdebug1.3 also comes with a simple command line client based on the GDB protocol.
Start the debugger
To enable the Xdebug debugger, you mustPhp. ini
File. These configurations includeXdebug. remote_enable
Used to allow the debugger,Xdebug. remote_host
AndXdebug. remote_port
Specify the IP address and port number that the debugger should connect. If you want the debugger to initialize a session when an error occurs (php error or exception), you need to modifyXdebug. remote_mode
Configuration. The values allowed by this configuration item are:Req
(Default) let the debugger initialize the session orJit
Initialize a session only when an error occurs.
After completing the preceding configuration, you will find that Xdebug does not automatically start a debugging session when the script is running. You also need to follow the methods below to activate the Xdebug debugger.
-
When running a script from a command line, you need to set an environment variable, as described below
Export XDEBUG_CONFIG = "idekey = session_name" php myscript. php
You can also configure
Xdebug. remote_host
,
Xdebug. remote_port
,
Xdebug. remote_mode
And
Xdebug. remote_handler
These options:
Export XDEBUG_CONFIG = "idekey = session_name remote_host = localhost profiler_enable = 1"
All the configuration items you set can also be set in the php. Ini file.
-
If you want to debug a script accessed through a browser, you only need to add
XDEBUG_SESSION_START = session_name
Pass the parameters. In the next section, you will see how a debugging session works in a browser window.
-
Another method to activate xdebug is to install one of the following three browser extensions when the browser is running. Each of the following extensions allows you to enable the debugger by clicking a button. These extensions are as follows:
- The simplest Xdebug
This extension is used on Firefox to make debugging easier with IDE. You can find this extension at https://addons.mozilla.org/en-us/firefox/addon/the-easiest-xdebug.
- Xdebug Helper for Chrome
This extension runs on the Chrome browser. It will help you click a button to allow/disable debugging and performance analysis. You can.
- Xdebug Toggler for Safari
This extension runs on Safari, allowing you to automatically start the Xdebug debugging process in Safari, and you can find this extension https://github.com/benmatselby/xdebug-toggler on Github.
- Xdebug launcher for Opera
This extension runs on Opera and allows you to enable an Xdebug session on Xdebug.
Before starting to execute the script, you must first tell the client to receive the debugging connection. Please check the documentation of the client you are using to obtain how to do this. To use the bound client, first install it. After installation, you can run the command"
Debugclient
"Command. If you want to use the GDB command set to debug your script, make sure that you are using the client bound to Xdebug1.3.
After the debugclient starts running, it will display the following information and wait for the source to wait until the debug server connection arrives for initialization:
Xdebug Simple DBGp client (0.10.0) Copyright 2002-2007 by Derick Rethans.-libedit support: enabled Waiting for debug server to connect.
After the connection is complete, the debug server displays the following output:
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> <opyright> <! [CDATA [Copyright (c) 2002-2007 by Derick Rethans]> </copyright> </init> (cmd)
Then you can use the command set described in the DBGp document to perform operations. When the script execution ends, the debugging server will disconnect the client and restore it to the status waiting for new connection requests.
Establish a connection
For a single developer with a static IP address
Xdebug is used for remote debugging. Xdebug acts as a program embedded in PHP and acts as a client, while IDE acts as a server. The following dynamic diagram shows the connection creation process.
- The IP address of the server is 10.0.1.2. The HTTP protocol is used and the port is 80.
- IDE is on a machine with the IP address 10.0.1.42,
Xdebug. remote_host
Set to 10.0.1.42
- The IDE listens to Port 9000. Therefore,
Xdebug. remote_port
Set to 9000
- The HTTP request is initiated from the server running the IDE.
- Connect Xdebug to 10.0.1.42: 9000
- Start Debugging and return an HTTP response
Multiple developers use non-fixed IP addresses
IfXdebug. remote_connect_back
The connection creation process is different for commands:
- The IP address of the server is 10.0.1.2 and port 80.
- IDE runs on a computer with a dynamic IP address.
Xdebug. remote_connect_back
1
- The IDE listens to Port 9000. Therefore, configure
Xdebug. remote_port
Is 9000
- Send an HTTP request. Xdebug checks the IP address in the HTTP header.
- Start Debugging and generate an HTTP response
HTTP debugging session
When using the browser for debugging, Xdebug supports the cookie-based session tracking function.
- When the parameter
XDEBUG_SESSION_START = name
Is appended to the URL address, Xdebug will setXDEBUG_SESSION
The value is a parameter.XDEBUG_SESSION_START
Cookie of the specified name. The Cookie expires in one hour.DBGp
The protocol will also pass the same value in the initialization package, so that you can connect to the setIdekey
The client of the property.
- When
XDEBUG_SESSION_START
GET (POST) variable orXDEBUG_SESSION
Xdebug will try to connect to debugcliet.
- To stop the xdebug session, you only need to pass one
XDEBUG_SESSION_STOP
Then Xdebug will not attempt to connect to the debugclient.
Multi-user debugging
Xdebug only allows you to use the specified IP address (Xdebug. remote_host
) To remotely debug the connection. It will not automatically connect back to the IP address of the machine that runs the access in the browser, unless you useXdebug. remote_connect_back
Command.
If your developers develop on different projects on the same server, you can use
. Htaccess
Function
Xdebug. remote_host
Command, configuration
Php_value xdebug. remote_host = 10.0.0.5
. However, if multiple developers develop on the same code,
. Htaccess
This feature cannot be completed.
There are two solutions to this problem. The first one is that you can use the DGBp proxy. For details about how to use this proxy, refer to this article for multi-user debugging. You can download this proxy at the site of ActiveState. Here are more documents in the Komodo FAQ.
The second solution is available
Xdebug. remote_connect_back
Configuration item (introduced after Xdebug 2.1 ).
Related configuration
Xdebug. extended_info
Type: integer, Default value: 1
Control whether Xdebug should force the PHP interpreter to use the 'extended _ info' mode. This allows Xdebug to use the remote debugger to set breakpoints for files or rows. This option is usually disabled when stack tracing or performance debugging is performed on the script, because some debugging attributes added to PHP will slow down script execution and affect the final result. This attribute can only be
Php. ini
File.
Ini_set ()
Function.
-
Xdebug. idekey
Type: string, Default value:
Complex
Control Xdebug should be passed
DBGp
Debug the IDE key of the processor. Environment-based configuration is used by default. First,
DBGP_IDEKEY
Will be used, followed by USER and USERNAME. By default, the configuration value found for the first time in the environment variable is used. If the configuration cannot be found, the default ''is used ''. If this option is set, it overwrites the environment variable configuration.
-
Xdebug. remote_autostart
Type: boolean, Default value: 0
Generally, you need to use the specified http get/POST variable to activate the remote debugging function of Xdebug. When this parameter is set to 1, Xdebug always tries to connect to the debugging client during script execution, even if no GET/POST/COOKIE variable is set. =
-
Xdebug. remote_connect_back
Type: boolean, Default value: 0, Introduced in Xdebug> 2.1
If yes,
Xdebug. remote_host
The setting will be invalid, and Xdebug will try to connect to the debugging client of the computer that sends the HTTP request. It will check
$ _ SERVER ['remote _ ADDR ']
Variable to find the IP address used. Please note that there is no available filter. Anyone connected to webserver can start a debugging session, even if their IP address and
Xdebug. remote_host
Not the same.
-
Xdebug. remote_cookie_expire_time
Type: integer, Default value: 3600, Introduced in Xdebug> 2.1
This option is used to control the time available for debugging sessions.
-
Xdebug. remote_enable
Type: boolean, Default value: 0
This option controls whether remote debugging is allowed. If a connection cannot be established, the script will continue to be executed, just as the value of this configuration is 0.
-
Xdebug. remote_handler
Type: string, Default value: dbgp
This value can be
Php3
Used to debug the output using the old PHP 3 style,
Gdb
The debugger interface that allows the use of GDB or
Dbgp
Protocol.
DBGp
The protocol is the only supported protocol.
The code is as follows: |
Copy code |
Note: Xdebug 2.1 and later versions only support
Dbgp Protocol.
|
-
Xdebug. remote_host
Type: string, Default value: localhost
Select the host on which the debugging client runs. This option can use the host name or IP address. If
Xdebug. remote_connect_back
This option is ignored.
-
Log opened at 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: req
Select when to establish the debugging connection. This option has two different values:
Req
Xdebug connects to the debugging client immediately when the script execution starts.
Jit
Xdebug only tries to connect to the debugging client when a script error occurs.
- Xdebug. remote_port
Type: integer, Default value: 9000
The port number used by Xdebug to connect to the client. The default port is 9000.
Related functions
Bool xdebug_break ()
Sends a breakpoint to the debugging client. This function allows the debugger to set a breakpoint on the specified line.