Xdebug
Xdebug
Xdebug
What is Xdebug?
Xdebug is a PHP extension providing:
Enhanced variable display
Enhanced stack traces
Function traces
Code coverage analysis
Remote debugging
Code profiling
What we are talking about
Code Coverage Analysis:
Tells you which lines of script (or set of scripts) have been
executed during a request. With this information you can
Remote debugging:
Step through debugging with a remote client via the DBGP
protocol
Code profiling:
Finding bottlenecks in your code and visualize those with an
external tool such as KCacheGrind or WinCacheGrind.
Remote Debug Configuration
extended_info – Enabled by default.
Allows breakpoints.
idekey – Identifier for the debug session.
Most clients will restrict to requests from
a single idekey value.
remote_autostart – Disabled by default.
Will start remote debugging with every
request.
Remote Debug Configuration
remote_enable – Defaults to 0 (off).
Enable remote debugging
remote_handler – Defaults to DBGP.
You should never have to use anything
else so just leave it.
remote_host – Remote host with which
Xdebug will connect at the start of an
Xdebug session.
Remote Debug Configuration
remote_log – Default value “”. Log all
remote debugger communication. You
will probably never need this unless you
are writing a client or have connectivity
issues.
remote_mode – Default value is “req”.
Determines how the session is initiated.
“req” will start the session with every
request. “jit” will start the session when
an error condition occurs.
Remote Debug Configuration
remote_port – Defaults to 9000. TCP/IP
port of the remote client which which
Xdebug will connect. Most clients
default to 9000 so unless you are forced
to debug multiple remote machines, just
leave it.
Xdebug Profiling
Find bottlenecks
Timings for optimization
Similar to Cachegrind but no memory
data
Output format is standard so it can be
read by standard Cachegrind tools:
Kcachegrind, QCacheGrind,
WinCacheGrind, IDE plugins, etc.
Profiling Configuration
profiler_append – Default value 0 (off).
Append the profiler output to the same file if
the profile_output_name will allow.
profiler_enable – Default value 0 (off).
Enable profiling for all requests and script
executions. If you are doing web request
profiling, use profiler_enable_trigger
instead. This should normally be used only
for CLI profiling and configuring via
environment variable.
Profiling Configuration
profiler_enable_trigger – Default value 0
(off). Allow triggering of profiling via
request query parameter or cookie with
the name XDEBUG_PROFILE. The
value is optional and ignored.
profiler_output_dir – Defaults to “/tmp”.
The directory in which the profiler output
file will be written.
Profiling Configuration
profiler_output_name – Default value is
“cachegrind.out.%p” where %p is the
process ID of the process running the
profile. There are many variable options
like %s for the file name. See the
Xdebug documentation for details: http
://xdebug.org/docs/all_settings#
trace_output_name
Xdebug Remote Debugging
Line by line stepping through code.
Break points to stop at particular areas of
code.
Variable inspection to be able to see
variable values at a line of code. Death to
var_dump.
Variable setting to allow replacement of
variable values at runtime.
The single best way to troubleshoot bugs.
Code Coverage
Code coverage is measure up to which
the source code is being tested by a test
suite
If code coverage is high the source code
contains more bugs
If code coverage is less then sorce code
contains less bugs
Code Coverage Analysis
xdebug.coverage_enable
Type: boolean, Default value: 1, Introduced in
Xdebug >= 2.2 If this setting is set to 0, then
Xdebug will not set-up internal structures to
allow code coverage.
boolean xdebug_code_coverage_started()
Returns whether code coverage is active.
Returns whether code coverage has been
started.
Code Coverage Analysis
void xdebug_stop_code_coverage( [int
cleanup=true] )