100% found this document useful (1 vote)
274 views21 pages

PHP - Tek 2007 - Chicago, US Derick Rethans - Dr@ez - No

This document discusses Xdebug, an open source PHP debugging tool. It provides information on installing Xdebug using PEAR or manually. It demonstrates how to enable and configure Xdebug to profile scripts, collect code coverage data, and trace script execution. Additionally, it shows how to analyze running scripts using the DBGp debugging protocol and debug with an IDE.

Uploaded by

Dan Previte
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
274 views21 pages

PHP - Tek 2007 - Chicago, US Derick Rethans - Dr@ez - No

This document discusses Xdebug, an open source PHP debugging tool. It provides information on installing Xdebug using PEAR or manually. It demonstrates how to enable and configure Xdebug to profile scripts, collect code coverage data, and trace script execution. Additionally, it shows how to analyze running scripts using the DBGp debugging protocol and debug with an IDE.

Uploaded by

Dan Previte
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Welcome!

php|tek 2007 - Chicago, US

Derick Rethans - [email protected]

http://files.derickrethans.nl/xdebug-phptek7.pdf
About Me

● Dutchman living in Norway


● eZ Systems A.S.
● eZ Components project lead
● PHP development
● mcrypt, input_filter, date/time support, unicode
● QA
I Do Need a Debugger

● Xdebug: An Open Source debugging tool


● About 4 years old
● Version 2 is about to be released
● Works (at least) on Linux and Mac and Windows
Installing Xdebug
Compiling

With PEAR:
● pear install xdebug-beta
Without PEAR:
● wget http://xdebug.org/files/xdebug-2.0.0RC3.tgz
● tar -xvzf xdebug-2.0.0RC3.tgz
● cd xdebug-2.0.0RC3
● phpize
● ./configure
● make
● make install
Installing Xdebug
Enabling
● in php.ini add: zend_extension=/full/path/to/xdebug.so
● Use zend_extension_debug for debug builds of PHP
Installing Xdebug
On Windows
● Download the .dll for your PHP version from http://pecl4win.php.net/
● in php.ini add: zend_extension_ts=c:\php\xdebug.dll
Installing Xdebug
Gotchas
● --enable-versioning prevent Xdebug from loading
● Zend's extensions (optimizer, debugger, cache) prohibit Xdebug (and other non-
Zend zend-extensions) from loading
Help By Error Messages

... is kinda useles.

xdebug.collect_params=1 and xdebug.show_local_vars=1


Demo

demo
How Much Time Does It Take

<pre>
<?php
require_once 'ezc/Base/base.php';

function __autoload( $className )


{
ezcBase::autoload( $className );
}

$cfg = ezcConfigurationManager::getInstance();
$cfg->init( 'ezcConfigurationIniReader', dirname( __FILE__ ) . '/examples' );

echo "Time Index: ", xdebug_time_index(), "\n";


$pw = $cfg->getSetting( 'settings', 'db', 'password' );
echo "The password is <$pw>.\n";
echo "Time Index: ", xdebug_time_index(), "\n";
?>
How Much Memory Does It Use

<pre>
<?php
require 'ezc_mail_setup.php';
error_reporting(E_ALL);

$parser = new ezcMailParser();


$set = new ezcMailFileSet( array( dirname(__FILE__).'/ezcmailtest.mail' ) );
echo "Memory: ", xdebug_memory_usage(), " bytes\n\n";

$mail = $parser->parseMail( $set );


foreach( $mail as $mailPart )
{
echo "From: {$mailPart->from->email}\n";
echo "Subject: {$mailPart->subject}\n";
}
unset( $mail );

echo "\nMaximum Memory: ", xdebug_peak_memory_usage(), " bytes\n";


?>
Execution trace

Available settings:
xdebug.auto_trace=1
xdebug.trace_output_dir=/tmp
xdebug.collect_vars=1
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.trace_options=1
xdebug.trace_output_name=crc32 # crc32, timestamp, pid
Demo

demo
What Code Do I Use

Available functions:
xdebug_start_code_coverage();
xdebug_get_code_coverage();
xdebug_stop_code_coverage();
What Code Do I Use

Options to xdebug_start_code_coverage():
● XDEBUG_CC_UNUSED: Enables scanning of code to figure out which line has
executable code.
● XDEBUG_CC_DEAD_CODE: Enables branch analyzation to figure out whether
code can be executed.

http://kossu/coverage/index.html
Profiling
KCacheGrind's Flat Profile and Call List

xdebug.profiler_enable=1 ; enable profiler


xdebug.profile_output_dir=/tmp ; output directory
xdebug.profile_output_name=crc32 ; file extension
Profiling
KCacheGrind's Call Graph and Source Annotations

● Call graph
● Area shows time spend
● Stacked to show callees
● Source annotations
● Number of calls
● Total time per function
Demo

demo
Analyzing Running Scripts

● DBGp, common Debugging protocol


● Cross-language: PHP, Python, Perl...
● Supported in Xdebug 2
● Clients: Komodo, Maguma Workbench, TruStudio (PHP Eclipse Plugin) and many
other smaller ones

Let's demo this...


Demo

demo
Resources

Xdebug site: http://xdebug.org


Xdebug documentation: http://xdebug.org/docs.php
DBGp specification: http://xdebug.org/docs-dbgp.php

Questions?: [email protected]

You might also like