PhpStorm 2024.3 Help

Debug in the Just-In-Time mode

PhpStorm supports the use of Xdebug in the Just-In-Time (JIT) mode so it is not attached to your code all the time but connects to PhpStorm only when an error occurs or an exception is thrown. Depending on the Xdebug version used, this operation mode is toggled through the following settings:

The mode is available both for debugging command-line scripts and for web server debugging.

Configure Xdebug for using in the Just-In-Time mode

Depending on whether you are going to debug command-line scripts or use a Web server, use one of the scenarios below.

Command-line scripts

For debugging command-line scripts, specify the custom -dxdebug.remote_mode=jit (for Xdebug 2) or -dxdebug.start_upon_error=yes (for Xdebug 3) directive as an additional configuration option:

  1. In the Settings dialog (Ctrl+Alt+S) , go to PHP.

  2. From the PHP executable list, choose the relevant PHP interpreter and click the Browse button next to it.

  3. In the CLI Interpreters dialog that opens, click the Browse button next to the Configuration options field in the Additional area.

  4. In the Configuration options dialog that opens, click the Add button to add a new entry.

    Type xdebug.start_upon_error in the Configuration directive field and yes in the Value field.

    Type xdebug.remote_mode in the Configuration directive field and jit in the Value field.

    When you click OK, you return to the CLI Interpreters dialog where the Configuration options field shows -dxdebug.remote_mode=jit (for Xdebug 2) or -dxdebug .start_upon_error=yes (for Xdebug 3).

Web server debugging

  1. In the main menu, go to Run | Web Server Debug Validation.

  2. In the Validate Remote Environment that opens, choose the Web server to validate the debugger on.

    • Choose Local Web Server or Shared Folder

      Path to create validation script

      In this field, specify the absolute path to the folder under the server document root where the validation script will be created. For web servers of the Inplace type, the folder is under the project root.

      The folder must be accessible through HTTP.

      URL to validation script

      In this field, type the URL address of the folder where the validation script will be created. If the project root is mapped to a folder accessible through HTTP, you can specify the project root or any other folder under it.

    • Choose Remote Web Server

      Path to create validation script

      In this field, specify the absolute path to the folder under the server document root where the validation script will be created. The folder must be accessible through HTTP.

      Deployment server

      In this field, specify the server access configuration of the type Local Server or Remote Server to access the target environment. For more information, refer to Connect to a web server.

      Choose a configuration from the list or click Browse the Browse button in the Deployment dialog.

  3. Click Validateto have PhpStorm create a validation script, deploy it to the target remote environment, and run it there.

  4. Open the php.ini file which is reported as loaded and associated with Xdebug.

  5. In the php.ini file, find the [xdebug] section.

    Change the value of the xdebug.start_upon_error from the default default to yes.

    Change the value of the xdebug.remote_mode from the default req to jit.

Debugging session

Set the breakpoints and launch a debugging session, as described in Initiating a Debugging Session or Debug with a PHP web page debug configuration.

Xdebug connects to PhpStorm in the following two cases:

  • When an error occurs. In this case, Xdebug stops on the line right after the error condition. The reason for that is that PhpStorm first has to run the erroneous code before it knows something is wrong.

  • When an exception is thrown. If the exception is handled, Xdebug breaks at the first line of the catch block if there is one, or at the finally block.

Last modified: 11 October 2024