Phpstorm Xdebug Postman



Postman started out as an API development tool, but has developed more into, as they put it, an 'API Development Environment'.

Jan 19, 2020 Requirements: You already need to configure PhpStorm with xdebug and php Here How to Do that: then when requesting from POSTMAN just add XDEBUGSESSIONSTART=PHPSTORM to the query string and PHPStorm will catch the debug session. Browser Xdebug helper plug-in mode Introduction to advantages and disadvantages. Advantage: No need for phpstorm to configure debug configuration and servers; As long as the configuration is consistentidekey=PHPSTORMOr add to the cookieXDEBUGSESSION=PHPSTORM. May 26, 2015 Nice and easy, this. Set the url with?XDEBUGSESSIONSTART=PHPSTORM and set a header Cookie: XDEBUGSESSION=PHPSTORM. 3 thoughts on “ Using xDebug with POSTMAN.

  1. PhpStorm supports debugging with the two most popular tools: Xdebug and Zend Debugger. These tools can not be used at the same time because they block each other. To avoid this problem, you must update the appropriate sections of the php.ini file, as described in Configuring Xdebug.
  2. Xdebugdevilboxphpstormpostman.md The tutorial got a new home, head over to the newly created repo (for more flexibility and better interaction). This comment has been minimized.

An over-simplified description is it allows you to create and save requests to test your API. You can then save your requests as a *collection* and share or publish them for others to use.

It supports API calls for all request types, fine control over headers, common authentication methods, and long list of other features that could fill an article... but I wanted to write specifically about using Xdebug with Postman.

How to trigger Xdebug when working with Postman

Recently, I was using Postman to troubleshoot an [API Platform](https://api-platform.com/) project and needed to trigger a Xdebug session in my IDE, [PhpStorm](https://www.jetbrains.com/phpstorm/).

Typically, I rely on a browser extension to trigger Xdebug, however Postman is its own application, so I could not rely on browser extensions.

Fortunately, there's an easy solution: Add `XDEBUG_SESSION_START=PHPSTORM` to the query string and PHPStorm will catch the debug session as it would if you were using a browser extension.

For example, if you are working on `http://localhost:8000/api/users`, simply append the URL with the query string mentioned above to initiate a debug session:

Now you can set breakpoints and debug as you would if you were working in a browser.

Besides debugging the entire application, you can debug separate HTTP Requests. This is helpful when you are actually interested in a specific page that is accessed in a number of steps, but for this or that reason you cannot specify this page as the start page for debugging, for example, because you need to 'come' to this page with certain data.

To debug PHP HTTP requests in PhpStorm, you can use the following methods:

  • Compose and debug the request via the HTTP client in the code editor, which is the recommended approach.

  • Use the PHP HTTP Request run configuration. Based on the configuration settings, PhpStorm composes the request to run.

Prepare the debugging engine

Phpstorm xdebug postman server
  • Before you start debugging, make sure that you have a debugging engine installed and configured properly. 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.

    Open the active php.ini file in the editor:

    1. In the Settings/Preferences dialog Ctrl+Alt+S, click PHP.

    2. On the PHP page that opens, click next to the CLI Interpreter field.

    3. In the CLI Interpreters dialog that opens, the Configuration file read-only field shows the path to the active php.ini file. Click Open in Editor.

Set the breakpoints

Phpstorm xdebug ssh

Breakpoints are source code markers used to trigger actions during a debugging session. Typically, the purpose behind setting a breakpoint is to suspend program execution to allow you to examine program data. However, PhpStorm can use breakpoints as triggers for a variety of different actions. Breakpoints can be set at any time during the debugging process. Your breakpoints don't affect your source files directly, but the breakpoints and their settings are saved with your PhpStorm project so you can reuse them across debugging sessions.

  1. Place the caret at the desired line of the source code.

    Breakpoints can be set in the PHP context inside php, html, and files of other types. Line breakpoints can be set only on executable lines, but not on comments, declarations, or empty lines.

  2. Do one of the following:

    • Click the gutter area at a line where you want to toggle a breakpoint.

    • From the main menu, choose Run | Toggle Line Breakpoint.

    • Press Ctrl+F8.

Debug the request via the HTTP client in the code editor

Php Docker Xdebug Phpstorm

Using the built-in HTTP Client, you can compose, execute, and debug HTTP requests directly from the PhpStorm code editor.

Phpstorm Xdebug PostmanXdebug
  1. Open an existing HTTP request file, or create a new one: in the File menu, point to New, and then click HTTP Request.

  2. Compose an HTTP request for the query that you need to debug.

  3. Position the caret at the request and press Alt+Enter or click in the editor gutter. From the popup menu, select PHP Debug <host>.

    If you have environments defined, select PHP Debug with ... and choose the environment in the popup menu. The selected environment will be used as the default one when executing or debugging the request later.

    PhpStorm will automatically add the XDEBUG_SESSION cookie to the request, execute it, and stop at the specified breakpoint.

When a request is executed, PhpStorm automatically creates a dedicated temporary HTTP Request run/debug configuration for it. You can save it as a permanent run/debug configuration if necessary.

Press Shift+F10 to run or Shift+F9 to debug the corresponding saved run/debug configuration at any moment without the need to open the request file in the editor. This can be useful if you are working on the web service endpoint implementation in a .php file and want to quickly test it by sending an HTTP request.

Create a debug configuration of the type PHP HTTP Request

Configure Xdebug Phpstorm

PhpStorm comprises the settings specified in this configuration into a PHP HTTP request. Note that using HTTP Client in editor for debugging HTTP requests is a more convenient and recommended approach.

  1. Open the Run/Debug Configuration dialog by doing one of the following:

    • From the main menu, choose Run | Edit Configurations.

    • Press Alt+Shift+F10, then press 0 to display the Edit Configuration dialog or select the configuration from the popup and press F4.

  2. Click on the toolbar or press Insert. From the list, select the PHP HTTP Request configuration type. The PHP HTTP Request dialog opens.

  3. Specify the configuration name.

  4. In the Server list, specify the debug server configuration to interact with the Web server where the application is executed. Select one of the existing configurations or click Browse and define a debug server configuration in the Servers dialog that opens as described in Create a PHP debug server configuration.

  5. In the URL field, complete the host element of the request to debug. Type the path relative to the host specified in the debug server configuration. As you type, PhpStorm composes the URL address on-the-fly and displays it below the field.

  6. Specify whether you want to bring any data to the target page. From the Request method list, choose the relevant request type:

    • To access the page without bringing any data, choose GET.

    • To access the page with some data saved in variables, choose POST and type the relevant variables in the Request body field.

      By default, the Project Encoding is used in requests' encoding if it is not specified explicitly, for example:

      header('Content-type: text/html;charset=utf-8');

      The Project Encoding is specified on the File Encodings page of the Settings/Preferences dialog Ctrl+Alt+S.

  7. In the Query field, type the query string of the request. This string will be appended to the request after the ? symbol.

  8. Click OK, when ready.

Phpstorm Setup Xdebug

Initiate a debugging session and examine the suspended program

Phpstorm Xdebug Postman Free

  1. To start debugging, click the Debug button on the toolbar.

  2. As soon as the debugger suspends on reaching the first breakpoint, examine the application by analyzing frames. A frame corresponds to an active method or function call and stores the local variables of the called method or function, the arguments to it, and the code context that enables expression evaluation. All currently active frames are displayed on the Frames pane of the Debug tool window, where you can switch between them and analyze the information stored therein in the Variables and Watches panes. For more details, see the section Examining a Suspended Program.

  3. Continue running the program and examine its frames as soon as it is suspended again.

    • To control the program execution manually, step through the code using the commands under the Run menu or toolbar buttons: Step IntoF7, Step OutShift+F8, Step OverF8, and others. For more details, see Step through the program.

    • To have the program run automatically up to the next breakpoint, resume the session by choosing Run | Debugging Actions | Resume Program or pressing F9.