Debugging overview

PHP Tools for Visual Studio extends Visual Studio with PHP debugging capabilities. The debugging engine takes advantage of Xdebug PHP extension.

For general information about debugging with Visual Studio, see Debugging in Visual Studio.

Requirements

  • Xdebug must be configured within your PHP installation in order to make debugging functionality working. For more information, see Configuring Xdebug

  • Xdebug extension must operate on TCP port specified in PHP Tools options page. And your firewall must be properly setup to allow communication thhrough this port.

  • Use PHP Web Project or PHP Console Project (not ASP.NET Web Site)

Visual Debugger

Visual Debugger allows you to examine code while it is running and includes features that help you debug applications, including the following:

  • Breakpoints - Breakpoints are places in the code where the debugger will stop the application, allow you to view the current data state of the application, and then step through each line of code. For information, see Breakpoints.

  • Stepping - Once you have stopped at a breakpoint, you can run the code line by line (known as stepping through the code). Visual Debugger includes a number of features to help you step through your code, such as iterators that allow you to specify how many times to step through a loop before stopping again. For more information, see Code Stepping Overview.

  • Data Viewing - Visual Debugger gives you many different options for viewing and tracking data while the application is running. The debugger allows you to modify the data while the application is stopped in break mode and then continue to run the application with the modified data. For more information, see Viewing Data in the Debugger.

Debugging PHP Web Project

With a project, you can start debugging by pressing F5 (Debug | Start Debugging), which will launch the project as specified in the project properties (Startup page, Server).

Pressing Ctrl+F5 (Debug | Start without Debugging). Often, code will run faster without the debugger attached, and starting it with these commands will also use the project settings.

Supported Servers

PHP Web Project have built in support for several development servers to simplify development. Go to project properties (right click on project node in the Solution Explorer, click Properties) to specify web server, which will be used when user starts PHP Web Project.

  • PHP 5.4+ built-in web server - Simple and fast web server used for web development. It can handle single request at one time and has support for several document file types. More information at PHP: Built-in web server. PHP Web Project utilize uses of the web server, so it sufficient to hit F5 and start debugging.

  • IIS Express - PHP Tools allows user to take advantage of IIS Express. Which is better option than PHP build-in web server as it can handle multiple requests at a time or you can take advantage of URL Rewriter Module. PHP Tools will configure binding, virtual directory and checks for PHP configuration automatically.

  • Custom Web Server. In case you have another web server, the options above are not sufficient or you need to debug PHP code remotly on another machine, it is possible just to enter server's URL and make use of it.

    Note: If you choose this option, PHP Tools for Visual Studio is not able to check configuration.

Debugging Console Project

PHP Tools for Visual Studio enables debugging of PHP command-line applications.

To launch your script with certain command-line arguments, provide them as a Debug property.

Right-click on your project in the Solution Explorer and choose Properties, then select the Debug tab. Here, you can provide the following options:

  • Command line arguments
  • PHP Options
  • Working Directory

Command line arguments - This text will be added to the command used to launch your script, appearing after your scripts name. The first item here will be available to your script as $argv[1], the second as $argv[2], and so on.

Note: The first argument $argv[0] is always the name that was used to run the script.

PHP Options are arguments for the php itself, and appear before the name of your script. e.g. -d foo[=bar] Defines INI entry foo with a value 'bar'.

Working Directory property specifies the working directory from which the project is launched.

Features Summary

  • Multi-session debugging, Remote debugging
  • PHP, JavaScript and .NET debugging at once
  • Breakpoints, Conditional breakpoints
  • Step Into, Step Over, Step Out
  • Quick Watch support, Add To Watch
  • Edit values at run-time
  • Watch, Autos, Locals, Immediate Window
  • Call Stack Window
  • Text View, HTML View, XML View of variables value
  • Automatic file path mapping