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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in LaravelNotifications in LaravelMar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),