Xdebug document (7) remote debugging and xdebug document debugging _ PHP Tutorial

Source: Internet
Author: User
Tags derick
Xdebug document (7) remote debugging and xdebug document debugging. Xdebug documentation (7) remote debugging, xdebug documentation debugging Xdebug prompts that the debugging client interface is related to PHP running. This chapter explains how to set PHP and xdebug, and recommends some clients. Xdebug document (7) remote debugging and xdebug document debugging

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

Introduction

The remote Debugger of Xdebug allows you to check the data structure and interactively pass through and debug your code. The protocol has been opened, named DBGp. This protocol is implemented in xdebug2 and is no longer supported than the earlier GDB protocol.

Client

Xdebug2 is bundled with a simple command line tool using the DBGp protocol. Some other clients are doing well (free or commercial ).

  • Dev-PHP(IDE: Windows)
  • EclipsePlugin(IDE ).
  • EmacsPlugin(Editor Plugin ).
  • KDevelop(IDE: Linux (KDE); Open Source ).
  • ActiveState'sKomodo(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'sPHPEdit(IDE, from version 2.10: Windows; unzip CIAL ).
  • PHPEclipse(Editor Plugin ).
  • Devsense'sPHP Tools for Visual Studio(MS Visual Studio Plugin; Commercial ).
  • JetBrain'sPhpStorm(IDE; Commercial ).
  • Protoeditor(Editor: Linux ).
  • Pugdebug(Standalone client for Linux, Windows and Mac OS X; Open Source ).
  • VIMPlugin(Editor Plugin ).
  • Jcx software'sVS. Php(MS Visual Studio Plugin; Commercial ).
  • Xdebug Chrome App(Chrome Application; Open Source)
  • XDebugClient(Standalone client for Windows ).

The simple command line tool for debugging is bound todebugclientDirectory.

Start the debugger

To make the xdebug debugger take effect, you need to configure some settings in php. ini. This type of setting has xdebug. remote_enable to enable the debugger. xdebug. remote_host and xdebug. remote_port configure the IP address and port for the debugger to connect. The xdebug. remote_connect_back settings are also used by the development server to share 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 settings. The value of this setting is "req" (default). The height server initiates a session at the beginning of the script, or the jit value enables the session value to be generated when an error occurs.

After all these settings are completed, xdebug still fails to automatically start the debugging session when the script runs. You have three methods to activate the xdebug debugger:

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

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 as long as these values are isolated within one space:

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

You can use XDEBUG_CONFIG to set all settings in php. ini.

2. if you want to debug the script in the browser, you only need to addXDEBUG_SESSION_START=session_nameParameters. To replace the GET parameter, you can also set XDEBUG_SESSTION_START as The POST parameter or COOKIE parameter. For more information, see the next section.

3. to run PHP in a browser and activate the debugger, install the following browser plug-in. Each plug-in allows you to simply click the button to open the debugger. When these plug-ins are activated, they will directly set the cookie value of XDEBUG_SESSION, 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 only requires one click to help you enable or disable debugging. 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 enable an xdebug debugging session.

When you run the script, you want your client to receive debugging connections. for details about how to configure the client, see the document. For more information about how to use bundled simple clients, see the compilation and installation chapter. You can use the sub-branch to "debug the client ".

When the debugging client is started, it displays the following information and waits for the connection to be received by the debugging server:

Xdebug Simple DBGp client (0.10.0)

Copyright 2002-2007 by Derick Rethans.

-Libedit support: enabled

Waiting for debug server to connect.

When a connection is established, the debugging server outputs 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">

Xdebug

Derick Rethans

http://xdebug.org

Copyright (c) 2002-2007 by Derick Rethans

(Cmd)

Now you can use some command sets related to DBGp. When the script is running, the debugging server closes the connection with the client. Debug the client to recover and wait for a new connection.

Communication settings

Static IP/single development

During remote debugging, xdebug built in php acts as the client, while IDE acts as the server. The following animation shows how to create a communication channel:

  • The server IP address is 10.0.1.2 and the HTTP port is 80.
  • The IP address of the IDE 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
  • The HTTP request is started on the machine where the IDE is located.
  • Connect Xdebug to 10.0.1.42: 9000
  • When debugging starts, HTTP provides a response.

Unknown IP address/multiple developers

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

  • Server IP address and HTTP port 10.0.1.2: 80
  • The IP address of the machine where IDE is located is unknown, so xdebug. remote_connect_back is set to 1.
  • The IDE listens on port 9000, so xdebug. remote_port is set to 9000
  • When an HTTP request starts, Xdebug obtains the IP address through the HTTP header.
  • The IP address obtained by The Xdebug connection (10.0.1.42) is on port 9000.
  • Debug and run. HTTP provides a response.

HTTP debugging session

Xdebug allows you to use cookies to start tracing and debug sessions for browsers. This operation is similar to the following steps:

  • When the URL variable XDEBUG_SESSION_START = name is appended to the URL, or pass in the same name value through POST -- Xdebug sends out a cookie value "XDEBUG_SESSION" and the value is the value of XDEBUG_SESSION_START of the URL parameter. The Cookie value is valid for one hour. The DBGp protocol also transmits the same value to the "idekey" attribute in the initial packet when connecting to the debugging client.
  • Once XDEBUG_SESSION_START or XDEBUG_SESSION cookie is set, Xdebug tries to connect to the debugging client.
  • To stop the debugging session (and destroy the cookie attached), simply add the URL parameter XDEBUG_SESSION_STOP. Xdebug then no longer tries to create a client to connect to the high-Debug client.
Multi-user debugging

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

If developers have different projects on the same (development) server, you can set each project through the Apache. htaccess function.php_value xdebug.remote_host=10.0.0.5Use xdebug. remote_host.

There are two solutions. First, you can use the DBGp proxy. For how to use it, see Debugging with multiple users. You can download the agent software on the ActiveState's web site as part of the python remote debugging package. For more information, see the Komodo FAQ.

The second is to use xdebug 2.1's xdebug. remote_connect_back settings.

Settings

Xdebug. extended_info

Type:Integer, Default value:1

Control whether xdebug enables the "extended_info" mode of the PHP parser forcibly. This allows Xdebug to perform breakpoint debugging on the file/line number in remote debugging. When tracking or analyzing scripts, you usually want to disable this option, because the array generated by PHP will increase by 1/3 and slow down your script. This setting can only be set in php. ini, and cannot be set in ini_set.

Xdebug. idekey

Type:String, Default value:* Complex *

Control which IDE index values can be passed to the DBGp debugging processor by xdebug. By default, it is based on the set environment. First, DBGP_IDEKEY setting in the environment will be considered, followed by the USER and the final USERNAME. The default value is the first environment variable. If it is not found, the default value is "". If this value is set, it usually overwrites the environment variable value.

Xdebug. remote_autostart

Type:Boolean, Default value:0

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

Xdebug. remote_connect_back

Type:Boolean, Default value:0, StartsXdebug> 2.1

If the setting takes effect, the xdebug. remote_host setting ignores the setting, and Xdebug tries to connect the client that creates an HTTP request. It checks the $ _ SERVER ['remote _ ADDR '] variable and finds the IP address used. Keep in mind that it does not effectively filter. anyone can start the debugging session to connect to the server, even if their address does not match xdebug. remote_host.

Xdebug. remote_cookie_expire_time

Type:Integer, Default value:3600, StartsXdebug> 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 to try to communicate with the debugging client. the client sets xdebug. remote_host and xdebug. remote_port to listen to servers and ports. When it is set to 0, the script is only run and the connection cannot be established.

Xdebug. remote_handler

Type:String, Default:Dbgp

You can change to 'php3' to use the old php3 style debugger output. 'gdb 'can make gdb take effect similar to the debugger interface, or 'dbg' uses the debugger protocol. DBGp is the only supported protocol.

Note: version 2.1 or later only supports 'dbg' 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

->

Debugging (7) remote debugging. xdebug file debugging Xdebug prompts that the debugging client interface is in line with PHP running. This chapter explains how to set PHP and xdebug, and recommends some clients ....

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.