I have installed Xdebug on my computer. I can use Xdebug to debug the php page program and report an error. Next I will introduce Xdebug for remote error debugging. I have installed Xdebug on my computer. I can use Xdebug to debug the php page program and report an error. Next I will introduce Xdebug for remote error debugging.
Script ec (2); script
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 configurexdebug.remote_host
,xdebug.remote_port
,xdebug.remote_mode
Andxdebug.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 addXDEBUG_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
Xdebug
Derick Rethans
http://xdebug.org
<
Copyright (c) 2002-2007 by Derick Rethans
(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
Functionxdebug.remote_host
Command, Configurationphp_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 availablexdebug.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 bephp.ini
File.ini_set()
Function.
-
Xdebug. idekey
Type: string, Default value:Complex
Control Xdebug should be passedDBGp
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 andxdebug.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 bephp3
Used to debug the output using the old PHP 3 style,gdb
The debugger interface that allows the use of GDB ordbgp
Protocol.DBGp
The Protocol is the only supported protocol.
The Code is as follows: |
|
Note: Xdebug 2.1 and later versions only supportdbgp 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. Ifxdebug.remote_connect_back
This option is ignored.
-
Log opened at 2007-05-27 14:28:15 ->