Xdebug documentation (vii) remote debugging, Xdebug document debugging _php Tutorial

Source: Internet
Author: User
Tags derick php error

Xdebug documentation (vii) remote debugging, Xdebug document debugging

Xdebug prompts the debug client interface to be associated with the PHP run. This section explains how to set up PHP and Xdebug, and recommends some clients.


Xdebug's remote debugger allows you to examine data structures, interactively traversing and debugging your code. The agreement has been opened, called DBGP. The protocol was implemented in XDEBUG2 and replaced the old GDB similar protocol and was no longer supported.


XDEBUG2 bundles A simple command-line tool that uses the DBGP protocol. There are other clients that are doing very well (free or commercial).

  • dev-php (ide:windows)
  • Eclipse plugin (IDE).
  • Emacs plugin (Editor Plugin).
  • KDevelop (Ide:linux (KDE); Open Source).
  • ActiveState ' s Komodo (ide:windows, Linux, Mac; Commercial).
  • MACGDBP (Standalone Client for Mac OS X; FREE)
  • NetBeans (Ide:windows, Linux, Mac OS X and Solaris).
  • notepad++ Plugin (editor:windows).
  • Waterproof ' s phpedit (IDE, from version 2.10:windows; Commercial).
  • PHPEclipse (Editor Plugin).
  • Devsense ' s PHP Tools for Visual Studio (MS Visual Studio Plugin; Commercial).
  • Jetbrain ' s phpstorm (IDE; Commercial).
  • Protoeditor (Editor:linux).
  • Pugdebug (Standalone Client for Linux, Windows and Mac OS X; Open Source).
  • VIM plugin (Editor Plugin).
  • JCX Software ' s vs.php (MS Visual Studio Plugin; Commercial).
  • Xdebug Chrome App (Chrome application; Open Source)
  • xdebugclient (Standalone Client for Windows).

A simple command-line tool for debugging is bound to the debugclient directory in which Xdebug resides.

Start the debugger

For the Xdebug debugger to take effect, you need to configure some settings in php.ini. This type of Setup has xdebug.remote_enable on the debugger, Xdebug.remote_host and Xdebug.remote_port Configure IP addresses and ports for the debugger to connect. There are also xdebug.remote_connect_back settings for Development server sharing for use by multiple developers.

If you need a debugger to initiate a session when an error occurs (PHP error or exception), you also need to change the Xdebug.remot_mode settings. This setting allows the value to be "req" (the default), and the altimeter initiates a session at the beginning of the script, or the "JIT" value causes the session value to be generated when an error occurs.

After all these settings, Xdebug still fails to start the debugging session automatically when the script is run. You have three ways to activate the Xdebug debugger:

1. When you run the script in the command line, you need to set the environment variable to:

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 for the same environment variables as long as the values are isolated in one space:

Export xdebug_config= "Idekey=session_name remote_host=localhost profiler_enable=1"

All settings you can set in php.ini via Xdebug_config.

2. If you want to debug the script in the browser, only the URL will be added XDEBUG_SESSION_START=session_name 参数 . To override the Get parameter, you can also set the Xdebug_sesstion_start as the post parameter, or the cookie parameter. Please refer to the next section for details.

3. To run PHP in the browser and activate the debugger, the following browser plugins will be installed. Each plugin allows you to simply click the button to open the debugger. When these plugins are activated, they will directly set the Xdebug_session cookie value instead of the Xdebug_session_start.

The easiest Xdebug

The Firefox plugin has an IDE interface that makes debugging easy. Plugin address: https://addons.mozilla.org/en-US/firefox/addon/the-easiest-xdebug/.

Xdebug Helper for Chrome

The chrome plugin simply helps you turn debugging on or off with just one click. Plugin address: Https://chrome.google.com/extensions/detail/eadndfjplgieldjbigjakmdgkmoaaaoc.

Xdebug Toggler for Safari

The Safari plugin can automatically turn on Xdebug debugging. GitHub Address: Https://github.com/benmatselby/xdebug-toggler.

Xdebug launcher for Opera

The opera plugin allows you to open a Xdebug debugging session.

After you run the script and you want your client to be able to receive the debug connection, refer to the article to indicate how the client needs to configure the content. Refer to the compilation and installation chapter for a simple client with bundles. You can use the branch "Debug Client".

When the debug client starts, it displays the following information and waits for the connection to be received 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.

When the connection is formed, the debug server outputs the following information:


< p="">

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" >


Derick Rethans


Copyright (c) 2002-2007 by Derick Rethans


Now you can use some command sets about DBGP. When the script finishes running, the debug server closes the connection to the client. Debug client recovery waits for a new connection.

Communication settings

Static ip/Single Development

When debugging remotely, the xdebug that is built into PHP acts as a client, and the IDE serves as the server. The following motion diagram shows the establishment of the communication channel:

    • Server IP is, HTTP port 80
    • The IDE is located on IP, so xdebug.remote_host is set to
    • The IDE listens on port 9000, so Xdebug.remote_port is set to 9000
    • The HTTP request starts on the same machine as the IDE.
    • Xdebug Connecting to
    • Debugging begins, HTTP provides a response.

Unknown ip/multiple Developers

If the xdebug.remote_connect_back is used, it is connected in a somewhat different way:

    • Server IP and HTTP port
    • The IDE machine is unknown IP, so xdebug.remote_connect_back is set to 1.
    • The IDE listens on port 9000, so Xdebug.remote_port is set to 9000
    • The HTTP request starts and Xdebug gets the IP address through the HTTP header.
    • Xdebug connection gets to the IP ( on port 9000
    • Debug run, HTTP provides response.

HTTP Debugging session

Xdebug contains the ability to use cookies to launch trace debugging sessions to the browser. The work is similar to the following steps:

    • When the URL variable xdebug_session_start=name is appended to the URL, or the same name value is passed in via post--xdebug a cookie value of "xdebug_session" and the value is a URL parameter xdebug_session The _start value. The cookie value is valid for 1 hours. The DBGP protocol also uploads the same value to the "Idekey" attribute within the initial packet when it is connected to the debug client.
    • Once the Xdebug_session_start or Xdebug_session cookie is set, XDEBUG tries to connect to the debug client.
    • To stop the debugging session (and destroy the accompanying cookie) simply add the URL parameter xdebug_session_stop. Xdebug then no longer attempts to create a connection to the highly-tuned client.

Multi-User debugging

Xdebug allows only one IP address specified at remote debugging to connect to Xdebug.remote_host. It can't even go back to the browser's machine IP when the browser is running, unless you're using Xdebug.remote_connect_back.

If the developer's various projects are on the same (development) server, you can use the Xdebug.remote_host settings for each project through the Apache. htaccess feature Setting php_value xdebug.remote_host= .

There are two ways to fix this. First, you can use the DBGP agent. As for how to use it refer to the debugging with multiple users section. You can download the agent software at ActiveState's Web site as part of the Python remote debugging package. More documents are located in the Komodo FAQ.

The second is to use the Xdebug 2.1 xdebug.remote_connect_back setting.

Related Settings


Type: integer, default value: 1

Control Xdebug is mandatory to open the PHP parser "extended_info" mode, which allows xdebug in the remote debugging to do file/line number breakpoint debugging. When tracing or parsing a script you usually want to turn off this option because the PHP generated array will increase the size of your script by One-third. This setting can only be set in php.ini and cannot be set within Ini_set ().


Type: string, default value: *complex*

Controls which IDE index values can be passed by Xdebug to the DBGP debug processor. By default, settings are based on the environment. First, the environment setting Dbgp_idekey will be considered, followed by the user and the last username. The default value is to find the first environment variable. If you do not find it, the setting is default "". If the value is set, it typically overrides the environment variable value.


Type: boolean, default value: 0

In general, use a specified HTTP get/post variable to start remote debugging (refer to remote debugging). When set to 1 o'clock, Xdebug attempts to start a remote debugging session and tries to connect to a client, even if the Get/post/cookie variable does not exist.


Type: boolean, default: 0, starting with Xdebug > 2.1

If the setting takes effect, the Xdebug.remote_host setting is ignored and xdebug attempts to connect to the client making the HTTP request. It checks the $_server[' REMOTE_ADDR '] variable and finds the IP address used. Keep in mind that it has no effective filtering and anyone can start a debug session to connect to the server even if their address does not match xdebug.remote_host.


Type: integer, default: 3600, starting from Xdebug > 2.1

The time the cookie exists to increase or decrease the remote debugging session.


Type: boolean, default value: 0

The switch controls Xdebug attempts to communicate with the debug client by setting the Xdebug.remote_host and Xdebug.remote_port listening servers and ports when. When set to 0, the script is simply running and the connection cannot be built.


Type: string, default: DBGP

Can be changed to ' php3 ' using the old PHP3-style debugger output, ' gdb ' can make gdb take effect similar to the debugger interface, or ' DBGP ' uses the debugger protocol. The DBGP protocol is the only supported protocol.

Note: Version 2.1 or later only supports ' DBGP ' as a protocol.


Type: string, Default value:

If set to a value, it's used as filename to a file to which all remote debugger communications is logged. The file is always opened in Append-mode, and would therefore not being 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

- http://www.bkjia.com/PHPjc/1135469.html www.bkjia.com true http://www.bkjia.com/PHPjc/1135469.html techarticle Xdebug Documentation (vii) remote debugging, Xdebug document debugging Xdebug prompts the debug client interface to be associated with the PHP run. This section explains how to set up PHP and Xdebug, and recommends some clients. ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.