Xdebug Postman



Xdebug Postman

Let's learn how to debug php using XDebug in Sublime Text 3. The OS we are using is Ubuntu 18.04.

Postman Canary Be the first to experience new Postman features. If you want to be first in line to experience new features, download our latest Canary builds available for OSX (x64) / Windows (x86 or x64) / Linux (x86 or x64) for a sneak peek. Our Canary builds are designed for early adopters, and may sometimes break. Download Postman Canary. PhpStorm supports debugging with two most popular tools: Xdebug and Zend Debugger. These tools cannot be used simultaneously because they block each other. To avoid this problem, you need to update the corresponding sections in the php.ini file as described in Configure Xdebug and Configure Zend Debugger. In my current set-up of XDebug, using PHPStorm and the Bookmarklet provided I'm able to get it working in both Chrome and Firefox - but as soon as I try with POSTman or any other REST client, I can't figure out how to get it started. Debugging with Postman. If you chose to use a browser plugin above, you’ll notice that it doesn’t work for Postman (at least not on Chrome), so you can either use PhpStorm’s bookmarklets or you can add?XDEBUGSESSIONSTART=PHPSTORM to the url you’re calling to trigger the debugger.

You can check this by listing the installed modules and grepping it. Or, you could also check the php version. It will list Xdebug if it is loaded.

You can check the default settings by going executing the command “Xdebug Settings – User”

In this example, I am setting the url as “http://localhost:8000” since that is where my PHP server is running

Start debugging by executing the command “Xdebug: Start Debugging (Launch Browser)”

This will also launch a browser url “http://localhost:8000/?XDEBUG_SESSION_START=sublime.xdebug” which starts a xdebug session

You can right click on any line and add a breakpoint. The breakpoint will be triggered when the control reaches the line.

If you are not seeing the breakpoints being triggered when you are hitting the endpoint from a REST client like Insomnia / Postman, chances are that the cookie is not set. Setting XDEBUG_SESSION=sublime.xdebug; Expires=null; Domain=localhost; Path=/ should likely resolve this issue.

You can also look into the log file /var/log/xdebug/xdebug.log for further debugging

  • Add Breakpoint - Ctrl+F8 or ⌘+F8
  • Run - Ctrl+Shift+F5 or ⌘+Shift+F5
  • Step Over - Ctrl+Shift+F6 or ⌘+Shift+F6
  • Step Into - Ctrl+Shift+F7 or ⌘+Shift+F7
  • Step Out - Ctrl+Shift+F8 or ⌘+Shift+F8

This section describes all available configuration settings available in Xdebug.

Unless specifically mentioneds, each setting can be set inphp.ini, files like 90-xdebug.ini, but also inApache's .htaccess and PHP-FPM's .user.ini files.

A select set of settings can be set through an XDEBUG_CONFIGenvironment variable. In this situation, the xdebug. part shouldbe dropped from the setting name. An example of this is:

integer xdebug.cli_color = 0#

If this setting is 1, Xdebug will color var_dumps and stack tracesoutput when in CLI mode and when the output is a tty. On Windows, the ANSICON tool needs to beinstalled.

If the setting is 2, then Xdebug will always color var_dumps and stacktrace, no matter whether it's connected to a tty or whether ANSICON isinstalled. In this case, you might end up seeing escape codes.

See this article forsome more information.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

string xdebug.client_discovery_header = '#

If xdebug.client_discovery_header is configured to be a non-empty string, then thevalue is used as key in the $_SERVER superglobal array to determinewhich header to use to find the IP address or hostname to use for 'connectingback to'. This setting is only used in combination withxdebug.discover_client_host and is otherwise ignored.

For example, if xdebug.client_discovery_header is set to FORWARD_HOST,then Xdebug will check $_SERVER['FORWARD_HOST'] before the$_SERVER['HTTP_X_FORWARDED_FOR'] and$_SERVER['REMOTE_ADDR'] variables.

string xdebug.client_host = localhost#

Configures the IP address or hostname where Xdebug will attempt to connect to when initiating adebugging connection. This address should be the address of the machine where your IDE or debuggingclient is listening for incoming debugging connections.

On non-Windows platforms, it is also possible to configure a Unix domain socket which is supported byonly a select view debugging clients. In that case, instead of the hostname or IP address, useunix:///path/to/sock.

If xdebug.discover_client_host is enabled then Xdebug will only use the value of this setting incase Xdebug can not connect to an IDE using the information it obtained from HTTP headers. In thatcase, the value of this setting acts as a fallback only.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

integer xdebug.client_port = 9003#

The port to which Xdebug tries to connect on the remote host. Port9003 is the default for both Xdebug and the Command Line Debug Client.As many clients use this port number, it is best to leave this settingunchanged.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

string xdebug.cloud_id = #

With this setting you configure Xdebug for use with Xdebug Cloud. It needs to match one of thetokens from your profilepage.

Your IDE needs to be configured with the same token for Xdebug and your IDE tocommunicate through Xdebug Cloud.

In PhpStorm you can find this setting under:
File | Settings | PHP | Debug | Xdebug Cloud for Windows and Linux
PhpStorm | Preferences | PHP | Debug | Xdebug Cloud for macOS

boolean xdebug.collect_assignments = false#

This setting, defaulting to 0, controls whether Xdebug should addvariable assignments to function traces. Assign-by-var (=&)assignments are included too.

boolean xdebug.collect_return = false#

This setting, defaulting to 0, controls whether Xdebug should write thereturn value of function calls to the trace files.

integer xdebug.connect_timeout_ms = 200#

The amount of time in milliseconds that Xdebug will wait for on anIDE to acknowledge an incoming debugging connection. The default value of 200ms should in most cases be enough. In case you often get dropped debuggingrequests, perhaps because you have a high latency network, or a development boxfar away from your IDE, or have a slow firewall, then you can should increasethis value.

Please note that increasing this value might mean that your requests seem to'hang' in case Xdebug tries to establish a connection, but your IDE is notlistening.

boolean xdebug.discover_client_host = false#

If enabled, Xdebug will first try to connect to the client that made theHTTP request. It checks the $_SERVER['HTTP_X_FORWARDED_FOR'] and$_SERVER['REMOTE_ADDR'] variables to find out which hostname or IPaddress to use.

If xdebug.client_discovery_header is configured, then the $_SERVERvariable with that configured name will be checked beforeHTTP_X_FORWARDED_FOR and REMOTE_ADDR.

If Xdebug can not connect to a debugging client as found in one of the HTTPheaders, it will fall back to the hostname or IP address as configured by thexdebug.client_host setting.

This setting does not apply for debugging through the CLI, as the$_SERVER header variables are not available there.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

Warning: Please note that there is no filteravailable, and anybody who can connect to the webserver will then be able tostart a debugging session, even if their address does not matchxdebug.client_host.

string xdebug.dump.* = Empty#

* can be any of COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION.These seven settings control which data from the superglobals is shown when anerror situation occurs.

Each of those php.ini setting can consist of a comma separated list ofvariables from this superglobal to dump, or * for all of them.Make sure you do not add spaces in this setting.

In order to dump the REMOTE_ADDR and the REQUEST_METHOD when an erroroccurs, and all GET parameters, add these settings:

boolean xdebug.dump_globals = true#

When this setting is set to true, Xdebug adds the valuesof the super globals as configured through the xdebug.dump.* to on-screen stacktraces and the error log (if enabled).

boolean xdebug.dump_once = true#

Controls whether the values of the superglobals should be dumped on allerror situations (set to 0) or only on the first (set to 1).

boolean xdebug.dump_undefined = false#

If you want to dump undefined values from the superglobals you should setthis setting to 1, otherwise leave it set to 0.

string xdebug.file_link_format = #

This setting determines the format of the links that are made inthe display of stack traces where file names are used. This allows IDEs to setup a link-protocol that makes it possible to go directly to a line and file byclicking on the filenames that Xdebug shows in stack traces. An example format might look like:

The possible format specifiers are:

SpecifierMeaning
%fthe filename
%lthe line number

For various IDEs/OSses there are some instructions listed on how to make this work:

Firefox on Linux

  • Open about:config
  • Add a new boolean setting 'network.protocol-handler.expose.xdebug' and set it to 'false'
  • Add the following into a shell script ~/bin/ff-xdebug.sh:Add to that one of (depending whether you have komodo, gvim or netbeans):
    • komodo $f -l $l
    • gvim --remote-tab +$l $f
    • netbeans '$f:$l'
  • Make the script executable with chmod +x ~/bin/ff-xdebug.sh
  • Set the xdebug.file_link_format setting to xdebug://%f@%l

Windows and netbeans

  • Create the file netbeans.bat and save it in your path (C:Windows will work):

    Note: Remove the last line if you don't have nircmd.

  • Save the following code as netbeans_protocol.reg:

    Note: Make sure to change the path to Netbeans (twice), as well as the netbeans.bat batch file if you saved it somewhere else than C:Windows.

  • Double click on the netbeans_protocol.reg file to import itinto the registry.
  • Set the xdebug.file_link_format setting to xdebug.file_link_format ='netbeans://open/?f=%f:%l'

string xdebug.filename_format = ...%s%n#

This setting determines the format with which Xdebug rendersfilenames in HTML stack traces (default: ...%s%n) and locationinformation through the overloaded xdebug_var_dump() (default:%f).

The possible format specifiers are listed in this table. The example output isrendered according to the full path/var/www/vendor/mail/transport/mta.php.

SpecifierMeaningExample Output
%aAncester: Two directory elements and filenamemail/transport/mta.php
%fFull path/var/www/vendor/mail/transport/mta.php
%nName: Only the file namemta.php
%pParent: One directory element and the filenametransport/mta.php
%sDirectory separator/ on Linux, OSX and other Unix-like systems, on Windows

integer xdebug.force_display_errors = 0#

If this setting is set to 1 then errors willalways be displayed, no matter what the setting of PHP's display_errorsis.

integer xdebug.force_error_reporting = 0#

Xdebug Postman

This setting is a bitmask, like error_reporting.This bitmask will be logically ORed with the bitmask represented by error_reportingto dermine which errors should be displayed. This setting can only bemade in php.ini and allows you to force certain errors from beingshown no matter what an application does with ini_set().

string xdebug.gc_stats_output_name = gcstats.%p#

This setting determines the name of the file that is used to dumpgarbage collection statistics into. The setting specifies the format with format specifiers, verysimilar to sprintf() and strftime(). There are several format specifiersthat can be used to format the file name.

See the xdebug.trace_output_name documentation for the supportedspecifiers.

integer xdebug.halt_level = 0#

This setting allows you to configure a mask that determineswhether, and which, notices and/or warnings get converted to errors. You canconfigure notices and warnings that are generated by PHP, and notices andwarnings that you generate yourself (by means of trigger_error()). For example,to convert the warning of strlen() (without arguments) to an error, you woulddo:

Which will then result in the showing of the error message, and the abortionof the script. echo 'Hi!n'; will not be executed.

The setting is a bit mask, so to convert all notices and warnings intoerrors for all applications, you can set this in php.ini:

The bitmask only supports the four level that are mentioned above.

string xdebug.idekey = *complex*#

Controls which IDE Key Xdebug should pass on to the debugging client orproxy. The IDE Key is only important for use with the DBGp Proxy Tool,although some IDEs are incorrectly picky as to what its value is.

The default is based on the DBGP_IDEKEY environment setting. Ifit is not present, the default falls back to an empty string.

If this setting is set to a non-empty string, it selects its value overDBGP_IDEKEY environment variable as default value.

The internal IDE Key also gets updated through debugging session managementand overrides the value of this setting as is explained in theStep Debugging documentation.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

string xdebug.log = #

Configures Xdebug's log file.

Xdebug will log to this file all file creations issues, Step Debuggingconnection attempts, failures, and debug communication.

Enable this functionality by setting the value to a absolute path. Make surethat the system user that PHP runs at (such as www-data if you arerunning with Apache) can create and write to the file.

The file is opened in append-mode,and will therefore not be overwritten by default. There is no concurrencyprotection available.

The log file will include any attempt that Xdebugmakes to connect to an IDE:

It includes the opening time (2020-09-02 07:19:09.616195), theIP/Hostname and port Xdebug is trying to connect to(localhost:9003), and whether it succeeded (Connected toclient :-)). The number in brackets ([2693358]) is theProcess ID.

It includes:

[2693358]
process ID in brackets
2020-09-02 07:19:09.616195
opening time

For Step Debugging:

For Profiling:

For Function Trace:

All warnings and errors are described on the Description of errors page, withdetailed instructions on how to resolve the problem, if possible. All errors are always logged throughPHP's internal logging mechanism (configured with error_login php.ini). All warnings and errors also show up in thediagnostics log that you can view by calling xdebug_info().

Step Debugger Communication

The debugging log can also log the communication between Xdebug and an IDE.This communication is in XML, and starts with the <init XMLelement:

The fileuri attribute lists the entry point of yourapplication, which can be useful to compare to breakpoint_setcommands to see if path mappings are set-up correctly.

Beyond the <init element, you will find the configuration offeatures:

And continuation commands:

You can read about DBGP - A common debugger protocol specification at its dedicated documation page.

The xdebug.log_level setting controls how much information islogged.

Note: Many Linux distributions now use systemd, whichimplements private tmp directories. This means that when PHPis run through a web server or as PHP-FPM, the /tmp directory isprefixed with something akin to:

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

integer xdebug.log_level = 7#

Configures which logging messages should be added to the log file.

The log file is configured with the xdebug.log setting.

The following levels are supported:

LevelNameExample
0CriticalsErrors in the configuration
1ErrorsConnection errors
3WarningsConnection warnings
5CommunicationProtocol messages
7InformationInformation while connecting
10DebugBreakpoint resolving information

Criticals, errors, and warnings always show up in thediagnostics log that you can view by calling xdebug_info().

Criticals and errors are additionally logged throughPHP's internal logging mechanism (configured with error_login php.ini).

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

integer xdebug.max_nesting_level = 256#

Controls the protection mechanism for infinite recursion protection.The value of this setting is the maximum level of nested functions that areallowed before the script will be aborted.

When the maximum nesting level is reached,an 'Error' exceptionis thrown.

integer xdebug.max_stack_frames = -1#

Controls how many stack frames are shown in stack traces, both onthe command line during PHP error stack traces, as well as in thebrowser for HTML traces.

string xdebug.mode = develop#

This setting controls which Xdebug features are enabled.

This setting can only be set in php.ini orfiles like 99-xdebug.ini that are read when a PHP process starts(directly, or through php-fpm), but not in .htaccess and.user.ini files, which are read per-request.

The following values are accepted:

off
Nothing is enabled. Xdebug does no work besides checking whetherfunctionality is enabled. Use this setting if you want close to 0overhead.
develop
Enables Development Aids including the overloaded var_dump().
coverage
Enables Code Coverage Analysis to generate code coverage reports, mainly incombination withPHPUnit.
debug
Enables Step Debugging. This can be used to step through your code while itis running, and analyse values of variables.
gcstats
Enables Garbage Collection Statistics to collect statistics about PHP's GarbageCollection Mechanism.
profile
Enables Profiling, with which you can analyse performance bottleneckswith tools like KCacheGrind.
trace
Enables the Function Trace feature, which allows you record every functioncall, including arguments, variable assignment, and return value that is madeduring a request to a file.

You can enable multiple modes at the same time by comma separating theiridentifiers as value to xdebug.mode: xdebug.mode=develop,trace.

You can also set the mode by setting the XDEBUG_MODE environmentvariable on the command-line; this will take precedence over the xdebug.mode setting, but will no change the value of the xdebug.mode setting.

string xdebug.output_dir = /tmp#

The directory where Xdebug will write tracing, profiling, and garbagecollection statistics to. This directory needs to be writable for the systemuser with which PHP is running.

This setting can be changed in php.ini, .htaccess(and equivalent files), and within a PHP file with ini_set().

In some cases (when profiling, or whenxdebug.start_with_request=yes with tracing), Xdebugcreates the file before the script runs. In that case, changes made throughini_set() will not be taken into account.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

integer xdebug.profiler_append = 0#

When this setting is set to 1, profiler files will not be overwritten whena new request would map to the same file (depending on the xdebug.profiler_output_name setting.Instead the file will be appended to with the new profile.

string xdebug.profiler_output_name = cachegrind.out.%p#

This setting determines the name of the file that is used to dumptraces into. The setting specifies the format with format specifiers, verysimilar to sprintf() and strftime(). There are several format specifiersthat can be used to format the file name.

See the xdebug.trace_output_name documentation for the supportedspecifiers.

This setting can additionally be configured through theXDEBUG_CONFIGenvironment variable.

Postman

boolean xdebug.scream = false#

If this setting is 1, then Xdebug will disable the @ (shut-up) operator so that notices, warnings and errors are no longer hidden.

integer xdebug.show_error_trace = 0#

When this setting is set to 1, Xdebug will show a stack trace wheneveran Error is raised - even if this Error is actually caught.

integer xdebug.show_exception_trace = 0#

When this setting is set to 1, Xdebug will show a stack trace wheneveran Exception or Error is raised - even if this Exception or Error is actually caught.

Error 'exceptions' were introduced in PHP 7.

integer xdebug.show_local_vars = 0#

When this setting is set to something != 0 Xdebug's generated stack dumpsin error situations will also show all variables in the top-most scope. Bewarethat this might generate a lot of information, and is therefore turned off bydefault.

string xdebug.start_upon_error = default#

Step Debugging can be activated when a PHP Notice or Warning is emitted, orwhen a Throwable(Exception/Error) is thrown, depending on the value of this setting:

yes

Initialise a debugging session when a PHP Notice or Warning is emitted, orwhen a Throwable is thrown.

no
default

Do not start a debugging session upon an error situation.

Xdebug Debug Postman

This setting is independent of xdebug.start_with_request, and therefore it isnot necessary to set xdebug.start_with_request=trigger.

string xdebug.start_with_request = default#

A Function Trace, Garbage Collection Statistics, Profiling, or Step Debuggingcan be activated at the start of a PHP request. Whether this happens depends onthe value of this setting:

yes

The functionality starts when the PHP request starts, and before any PHPcode is run.

For example xdebug.mode=trace andxdebug.start_with_request=yes starts a Function Trace for thewhole request.

no

The functionality does not get activated when the request starts.

You can still start a Function Trace with xdebug_start_trace(), Step Debugging with xdebug_break(), or Garbage Collection Statistics with xdebug_start_gcstats().

trigger

The functionality only gets activated when a specific trigger is presentwhen the request starts.

Xdebug Postman Download

The name of the trigger is XDEBUG_TRIGGER, and Xdebug checksfor its presence in either $_ENV (environment variable),$_GET or $_POST variable, or $_COOKIE(HTTP cookie name).

There is also a legacy fallback to a functionality specific trigger name:XDEBUG_PROFILE (for Profiling), XDEBUG_TRACE(for a Function Trace), and XDEBUG_SESSION (forStep Debugging).

Debug session management for Step Debugging is alsoavailable through XDEBUG_SESSION_START.

With xdebug.trigger_value you can control which specific trigger value willactivate the trigger. If xdebug.trigger_value is set to an emptystring, any value will be accepted.

default

The default value depends on xdebug.mode:

  • debug: trigger
  • gcstats: no
  • profile: yes
  • trace: trigger

integer xdebug.trace_format = 0#

Xdebug Postman

The format of the trace file.

ValueDescription
0shows a human readable indented trace file with:time index, memory usage, memory delta,level, function name,function parameters,filename and line number.
1writes a computer readable format which has twodifferent records. There are different records for entering a stack frame, andleaving a stack frame. The table below lists the fields in each type of record.Fields are tab separated.
2writes a trace formatted in (simple) HTML.

Fields for the computerized format:

Record type123456789101112 - ...
Entrylevelfunction #always '0'time indexmemory usagefunction nameuser-defined (1) or internal function (0)name of the include or require filefilenameline numberno. of argumentsarguments (as many as specified in field 11) - tab separated
Exitlevelfunction #always '1'time indexmemory usageempty
Returnlevelfunction #always 'R'emptyreturn valueempty

See the introduction for Function Trace for a few examples.

integer xdebug.trace_options = 0#

When set to '1' the trace files will be appended to, instead ofbeing overwritten in subsequent requests.

string xdebug.trace_output_name = trace.%c#

This setting determines the name of the file that is used to dumptraces into. The setting specifies the format with format specifiers, verysimilar to sprintf() and strftime(). There are several format specifiersthat can be used to format the file name. The '.xt' extension is always addedautomatically.

The possible format specifiers are:

SpecifierMeaningExample FormatExample Filename
%ccrc32 of the current working directorytrace.%ctrace.1258863198.xt
%ppidtrace.%ptrace.5174.xt
%rrandom numbertrace.%rtrace.072db0.xt
%s

script name 2

cachegrind.out.%scachegrind.out._home_httpd_html_test_xdebug_test_php
%ttimestamp (seconds)trace.%ttrace.1179434742.xt
%utimestamp (microseconds)trace.%utrace.1179434749_642382.xt
%H$_SERVER['HTTP_HOST']trace.%Htrace.kossu.xt
%R$_SERVER['REQUEST_URI']trace.%Rtrace._test_xdebug_test_php_var=1_var2=2.xt
%U$_SERVER['UNIQUE_ID'] 3trace.%Utrace.TRX4n38AAAEAAB9gBFkAAAAB.xt
%Ssession_id (from $_COOKIE if set)trace.%Strace.c70c1ec2375af58f74b390bbdd2a679d.xt
%%literal %trace.%%trace.%%.xt

2 This one is only available for trace file names since Xdebug 2.6.

3 New in version 2.2. This one is set by Apache's mod_unique_id module

string xdebug.trigger_value = '#

This setting can be used when xdebug.start_with_request is set totrigger, which is the default for Step Debugging and Function Trace.

In trigger mode, Xdebug will only start itsfunctionality when the XDEBUG_TRIGGER is set in the environment,or when the XDEBUG_TRIGGER GET, POST, or COOKIE variable isset.

Postman

The legacy names XDEBUG_SESSION (for Step Debugging),XDEBUG_PROFILE (for Profiling), and XDEBUG_TRACE(for Function Trace) can also be used instead of XDEBUG_TRIGGER.

Normally, Xdebug does not look at which value is actually used. If thissetting is set to a non-empty string, then Xdebug will only trigger if thevalue matches the value of this setting.

With the following settings:

Xdebug's profiler will only start when either the environment variableXDEBUG_TRIGGER is set to StartProfileForMe, the GETor POST variable XDEBUG_TRIGGER is set toStartProfileForMe, or when the cookie XDEBUG_TRIGGERhas the value StartProfileForMe.

See also:

xdebug.start_with_request#trigger
For how the triggering mechanism works, and which environment and server variables Xdebug acts on.

integer xdebug.var_display_max_children = 128#

Controls the amount of array children and object's properties are shownwhen variables are displayed with either xdebug_var_dump(),xdebug.show_local_vars or when making a Function Trace.

To disable any limitation, use -1 as value.

This setting does not have any influence on the number of children that issend to the client through the Step Debugging feature.

Xdebug Postman Extension

integer xdebug.var_display_max_data = 512#

Controls the maximum string length that is shownwhen variables are displayed with either xdebug_var_dump(),xdebug.show_local_vars or when making a Function Trace.

To disable any limitation, use -1 as value.

Xdebug Postman

This setting does not have any influence on the number of children that issend to the client through the Step Debugging feature.

integer xdebug.var_display_max_depth = 3#

Controls how many nested levels of array elements and object properties arewhen variables are displayed with either xdebug_var_dump(),xdebug.show_local_vars or when making a Function Trace.

The maximum value you can select is 1023. You can also use -1 asvalue to select this maximum number.

This setting does not have any influence on the number of children that issend to the client through the Step Debugging feature.

Setting the value to a high number could potentially result inPHP using up all the available memory, so use with caution.