IntelliJ IDEA 2018.2 Help

Debugging a PHP HTTP Request

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.

Debugging PHP HTTP requests in IntelliJ IDEA is supported through the PHP HTTP Request run configuration. Based on the configuration settings, IntelliJ IDEA composes the request to run.

Preparing the debugging engine

Before you start debugging, make sure that you have a debugging engine installed and configured properly. IntelliJ IDEA 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 Configuring Xdebug and Configuring Zend Debugger.

To open the active php.ini file in the editor:

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click PHP under Languages & Frameworks.

  2. On the PHP page that opens, click browseButton 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.

Setting the breakpoints

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, IntelliJ IDEA 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 IntelliJ IDEA project so you can reuse them across debugging sessions.

  1. Place the caret on 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 left gutter area at a line where you want to toggle a breakpoint.

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

    • Press Ctrl+F8.

Creating a debug configuration of the type PHP HTTP Request

IntelliJ IDEA agglutinates the settings specified in this configuration into a PHP HTTP request.

  1. Open the Run/Debug Configuration dialog box by doing one of the following:
    • On the main menu, choose Run | Edit Configurations.

    • Press Shift+Alt+F10, then press 0 to display the Edit Configuration dialog box or select the configuration from the pop-up window and press F4.

  2. Click icons general add svg on the toolbar or press Insert. From the drop-down list, select the PHP HTTP Request configuration type. The PHP HTTP Request dialog box opens.

  3. Specify the configuration name.

  4. In the Server drop-down 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 browseButton.png and define a debug server configuration in the Servers dialog box that opens as described in Creating a PHP Debug Server Configuration.

  5. In the URL text box, 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, IntelliJ IDEA composes the URL address on-the-fly and displays it below the text box.

  6. Specify whether you want to bring any data to the target page. From the Request method drop-down 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 text box.

      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, under the Editor node of the Settings / Preferences Dialog.

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

  8. Click OK, when ready.

Initiating a debugging session and examining the suspended program

  1. To start debugging, click the Debug button icons actions startDebugger svg 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 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 Into (F7), Step Out (Shift+F8), Step Over (F8), and others. For more details, see Stepping Through the Program.

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

Last modified: 20 November 2018

See Also