Xdebug debugger

Last updated on
10 May 2023

For advanced development, a debugger is necessary. A debugger will allow you to follow program execution and its effects, to observe the call stack of functions, and review the contents of variables at any point during execution.

Xdebug is the standard debugger in PHP, launched in 2007: Zend's "Introducing Xdebug" (Web Archive).

Some articles on setting up and using Xdebug in popular development environments:

PhpStorm

JetBrains supports non-commercial open source projects, and Drupal contributors with 35 or more issue credits gained over the past year can get a free PhpStorm license. See also Free PhpStorm licenses for Drupal contributors.

VS Code

Other tutorials

These are older tutorials, which may or may not work. Feel free to test them, and move up up under PhpStorm and VS Code tutorials above under its own header, if you find that they work with Xdebug 3.

Profiling

Profilers give you the ability to analyse your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. A profiler also collects information about how much memory is being used, and which functions and methods increase memory usage. Perfect for analysing slow request, long batch or migrate task.

Xdebug has options to enable profiling  : https://xdebug.org/docs/profiler.

GUI tools needed to analyse callgrind-compatible profiles files:

qcachegrind (win)

Alternate solutions

Xhprof

This php extension that provides profiling and a simple HTML based navigational interface: https://github.com/longxinH/xhprof/

Blackfire

SensioLabs & Plateform.sh provide a paid SaaS solution with extra features. It's free for students or Open Source project: https://www.blackfire.io/

Help improve this page

Page status: No known problems

You can: