PHP phpdbg - Interactive Debugger Complete Guide
Mahesh Waghmare 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.
Basic Usage
Start phpdbg
phpdbg
Load PHP File
exec test.php
Run Script
run
Interactive Mode
prompt> help
Debugging Commands
Basic Commands
help- Show helprun- Execute scriptstep- Step into functionnext- Step over linecontinue- Continue executionquit- Exit debugger
Variable Inspection
print $variable- Print variable valueinfo variables- List all variablesinfo locals- List local variables
Execution Control
break- Set breakpointclear- Clear breakpointlist- Show source codeframe- 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
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.
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 →