PHP phpdbg - Interactive Debugger Complete Guide

Mahesh Mahesh Waghmare
2 min read

phpdbg is PHP’s built-in interactive debugger. It allows you to step through code, set breakpoints, inspect variables, and debug PHP applications effectively.

This guide covers phpdbg from installation to advanced debugging techniques.

Introduction to phpdbg

phpdbg is a command-line debugger included with PHP 5.6+. It provides interactive debugging capabilities similar to gdb for C/C++.

Key Features:

  • Interactive debugging
  • Breakpoint support
  • Variable inspection
  • Step execution
  • Code evaluation

Use Cases:

  • Debugging PHP scripts
  • Understanding code flow
  • Inspecting variables
  • Testing code execution
  • Learning PHP internals

Installation

phpdbg comes with PHP. If PHP is installed, phpdbg should be available.

Verify Installation

phpdbg --version

Check Availability

which phpdbg
# or
where phpdbg

If not found, phpdbg may need to be enabled during PHP compilation.

Advertisement

Basic Usage

Start phpdbg

phpdbg

Load PHP File

exec test.php

Run Script

run

Interactive Mode

prompt> help

Debugging Commands

Basic Commands

  • help - Show help
  • run - Execute script
  • step - Step into function
  • next - Step over line
  • continue - Continue execution
  • quit - Exit debugger

Variable Inspection

  • print $variable - Print variable value
  • info variables - List all variables
  • info locals - List local variables

Execution Control

  • break - Set breakpoint
  • clear - Clear breakpoint
  • list - Show source code
  • frame - Show current frame

Setting Breakpoints

Line Breakpoint

break test.php:10

Function Breakpoint

break function_name

Conditional Breakpoint

break test.php:10 if $variable > 10
Advertisement

Advanced Features

Watch Expressions

Monitor variable changes during execution.

Code Evaluation

Execute PHP code in current context.

Stack Traces

Inspect call stack and execution flow.

Conclusion

phpdbg provides:

  • Interactive debugging for PHP
  • Breakpoint support for code inspection
  • Variable inspection capabilities
  • Step execution control

Key Points:

  • Included with PHP
  • Command-line interface
  • Supports breakpoints
  • Useful for debugging
  • Learning tool

phpdbg is a powerful tool for debugging PHP applications and understanding code execution.

Advertisement
Mahesh Waghmare

Written by Mahesh Waghmare

I bridge the gap between WordPress architecture and modern React frontends. Currently building tools for the AI era.

Follow on Twitter

Read Next