search
HomeBackend DevelopmentPHP TutorialXdebug document (7) Remote debugging, xdebug document debugging_PHP tutorial

Xdebug document (7) Remote debugging, xdebug document debugging

Xdebug prompts that the debugging client interface is connected to PHP running. This chapter explains how to set up PHP with xdebug, and recommends some clients.

Introduction

Xdebug's remote debugger allows you to inspect data structures, step through and debug your code interactively. The protocol is already open and is called DBGp. This protocol was implemented in xdebug2 and replaces an older GDB similar protocol that is no longer supported.

Client

Xdebug2 bundles a simple command line tool using the DBGp protocol. There are other clients that do a good job (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 bundled in the debugclient directory where xdebug is located.

Start debugger

To enable the xdebug debugger, you need to configure some settings in php.ini. Such settings include xdebug.remote_enable to enable the debugger, xdebug.remote_host and xdebug.remote_port to configure the IP address and port for the debugger to connect. There is also the xdebug.remote_connect_back setting for sharing the development server with multiple developers.

If you need the debugger to initiate a session when an error occurs (PHP error or exception), you also need to change the xdebug.remot_mode setting. Allowed values ​​for this setting are "req" (default), which causes the heightener to initiate a session at the beginning of the script, or "jit", which causes the session value to be generated when an error occurs.

After setting all this up, xdebug still fails to automatically start a debugging session as soon as the script is run. You have three ways to activate the xdebug debugger:

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

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 as the same environment variables by isolating these values ​​in a space:

export XDEBUG_CONFIG="idekey=session_name remote_host=localhost profiler_enable=1"

All settings you can set through XDEBUG_CONFIG in php.ini.

2. If you want to debug the script in the browser, just add XDEBUG_SESSION_START=session_name参数 to the URL. To replace the GET parameter, you can also set XDEBUG_SESSTION_START as the POST parameter or the COOKIE parameter. Please refer to the next chapter for details.

3. To run PHP in the browser and activate the debugger, you need to install the following browser plug-in. Each plug-in lets you launch the debugger with the click of a button. When these plugins are activated, they will directly set the XDEBUG_SESSION cookie value instead of XDEBUG_SESSION_START.

The easiest Xdebug

The Firefox plug-in has an IDE interface for easier debugging. Plug-in address: https://addons.mozilla.org/en-US/firefox/addon/the-easiest-xdebug/.

Xdebug Helper for Chrome

The Chrome plug-in helps you turn on or off debugging with just one click. Plug-in address: https://chrome.google.com/extensions/detail/eadndfjplgieldjbigjakmdgkmoaaaoc.

Xdebug Toggler for Safari

The Safari plug-in can automatically enable Xdebug debugging. Github address: https://github.com/benmatselby/xdebug-toggler.

Xdebug launcher for Opera

The Opera plug-in allows you to open an xdebug debugging session.

Before you run the script, you want your client to be able to receive debug connections. Please refer to the article to specify how the client needs to be configured. To use the bundled simple client please refer to the Compilation and Installation chapter. You can use the branch "debug client".

When the debug client starts, it will display the following message and wait 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 will output the following information:

Connect

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

(cmd)

Now you can use some command sets related to DBGp. When the script finishes running, the debugging server closes the connection with the client. The debug client resumes waiting for new connections.

Communication Settings

Static IP/single development

During remote debugging, xdebug built into PHP acts as the client, and the IDE acts as the server. The following animation shows the establishment of a communication channel:

  • The server IP is 10.0.1.2, HTTP port 80
  • The IP where the IDE is located is 10.0.1.42, so xdebug.remote_host is set to 10.0.1.42
  • The IDE listens on port 9000, so xdebug.remote_port is set to 9000
  • HTTP requests are initiated on the machine where the IDE is located.
  • Xdebug connects to 10.0.1.42:9000
  • Debugging starts and HTTP response is provided.

Unknown IP/Multiple developers

If xdebug.remote_connect_back is used, the connection method is slightly different:

  • Server IP and HTTP port 10.0.1.2:80
  • The machine where the IDE is located has an 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 obtains the IP address through the HTTP header.
  • The IP (10.0.1.42) obtained by Xdebug connection is on port 9000
  • Debug runs, HTTP provides response.

HTTP debugging session

Xdebug includes the function of using cookies to start a trace debugging session on 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 through POST - Xdebug sends a cookie value "XDEBUG_SESSION" and this value is the URL parameter XDEBUG_SESSION_START value. The cookie value is valid for 1 hour. The DBGp protocol also passes the same value to the "idekey" attribute within the initial packet when connecting to the debug client.
  • XDEBUG_SESSION_START or XDEBUG_SESSION cookie Once set, Xdebug will try to connect to the debugging client.
  • To stop a debugging session (and destroy accompanying cookies) simply add the URL parameter XDEBUG_SESSION_STOP. Xdebug then no longer attempts to create a connection to the highly debug client.

Multi-user debugging

Xdebug only allows an IP address specified during remote debugging to connect to xdebug.remote_host. It cannot connect back to the IP of the machine where the browser is running when the browser is running the test, unless you use xdebug.remote_connect_back.

If developers have various projects on the same (development) server, you can set each project through Apache's .htaccess function php_value xdebug.remote_host=10.0.0.5 and use the xdebug.remote_host setting.

There are two solutions here. First, you can use a DBGp proxy. As for how to use it, refer to the Debugging with multiple users chapter. You can download the agent software as part of the python remote debugging package at ActiveState's web site. More documentation is in the Komodo FAQ.

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

xdebug.extended_info

Type: integer, default value: 1

Control whether xdebug forcibly turns on the "extended_info" mode of the PHP parser, which allows Xdebug to perform file/line number breakpoint debugging on remote debugging. When tracing or profiling scripts you usually want to turn this option off because the arrays produced by PHP will increase by a third in size and slow down your script. This setting can only be set in php.ini, not in ini_set().

xdebug.idekey

Type: string, Default value: *complex*

Controls which IDE index values ​​can be passed by xdebug to the DBGp debug processor. The default is based on setting the environment. First the environment setting DBGP_IDEKEY is considered, then USER and finally USERNAME. The default value will be the first environment variable found. If it is indeed not found, the setting is the default "". If this value is set, it usually overrides the environment variable value.

xdebug.remote_autostart

Type: boolean, Default value: 0

Generally speaking, you need to use a specified HTTP GET/POST variable to start remote debugging (refer to Remote Debugging). When set to 1, Xdebug will attempt to start a remote debugging session and attempt to connect to a client, even if the GET/POST/COOKIE variable does not exist.

xdebug.remote_connect_back

Type: boolean, Default value: 0, since Xdebug > 2.1

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

xdebug.remote_cookie_expire_time

Type: integer, Default value: 3600, since Xdebug > 2.1

Used to increase or decrease the cookie existence time of the remote debugging session.

xdebug.remote_enable

Type: boolean, Default value: 0

This switch controls Xdebug's attempt to communicate with the debugging client by setting the xdebug.remote_host and xdebug.remote_port listening server and port. When set to 0, the script is simply run but the connection cannot be established.

xdebug.remote_handler

Type: string, Default: dbgp

Can be changed to 'php3' to use the old PHP3 style debugger output, 'gdb' to enable GDB similar to the debugger interface, or 'dbgp' to use the debugger protocol. DBGp protocol is the only supported protocol.

Note: Version 2.1 or above only supports 'dbgp' as the protocol.

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

->

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1135469.htmlTechArticleXdebug Document (7) Remote debugging, xdebug document debugging Xdebug prompt debugging client interface is linked to PHP running. This chapter explains how to set up PHP with xdebug, and recommends some clients. ...

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor