SlideShare a Scribd company logo
Welcome!




                       ConFoo
        Montréal, Canada - March 9th, 2011
 Derick Rethans - derick@derickrethans.nl - twitter:
                      @derickr
              http://derickrethans.nl/talks.html
                      http://joind.in/2783
About Me



Derick Rethans




●   Dutchman living in London
●   PHP development
●   Author of the mcrypt, input_filter, dbus, translit
    and date/time extensions
●   Author of Xdebug
●   Contributor to the Apache Zeta Components
    Incubator project (formerly eZ Components)
●   Freelancer doing PHP (internals) development
Development Aid
Live Debugging
Profiling
Xdebug Pimps Your Ride
Error Messages
     Warning: DOMDocument::load() [domdocument.load]: Document is empty in
     /home/httpd/presentations,
     line: 1 in /home/httpd/pres2/show2.php on line 165
     _________________________________________________________________________________________________
     |( ! ) Warning: DOMDocument::load() [domdocument.load]: Document is empty in /home/httpd/         |
     |presentations,_line:_1_in_/home/httpd/pres2/show2.php_on_line_165________________________________|
     |Call_Stack_______________________________________________________________________________________|
     |#|Time__|Memory_|Function_______________________________________________________|Location________|
     |1|0.0013|_787720|{main}(_)______________________________________________________|../show2.php:0__|
     |2|0.0102|1398552|Presentation->display(_$slideNr_=_NULL_)_______________________|../show2.php:114|
     |3|0.0103|1400336|DOMDocument->load( '/home/httpd/pres2/presentations/'|../show2.php:165|
     |_|______|_______|)______________________________________________________________|________________|




 ●     xdebug.collect_include=?
 ●     xdebug.var_display_max_children=?
       xdebug.var_display_max_data=?
       xdebug.var_display_max_depth=?
 ●     xdebug.file_link_format=?
       xdebug.file_link_format=gvim://f@l
       xdebug.file_link_format=txmt://open/?url=file://f&line=l
       xdebug.file_link_format=???://f?l Windows:
       http://forums.netbeans.org/topic20597.html#85639 Linux:
       http://xdebug.org/docs/stack_trace#file_link_format
Error Messages
Pimped-Up with CSS

 ________________________________________________________________________________________
 |( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/|
 |xdebug/docs/stack.php_on_line_66________________________________________________________|
 |Call_Stack______________________________________________________________________________|
 |#|Time___________________|Memory|Function_|Location_____________________________________|
 |1|____________0.0004_____|691504|{main}(_)|../stack.php:0_______________________________|
 |2|____________0.0006_____|699472|foo(_)___|../stack.php:82______________________________|
 |Dump_$_SERVER___________________________________________________________________________|
 |$_SERVER['REQUEST_URI'] |string_'/test/xdebug/docs/stack.php?level=7'_(length=35)______|
 |Variables_in_local_scope_(#2)___________________________________________________________|
 |                     $a |array (size=5)                                                 |
 |                         |                                                                |
 |                         | 42 => boolean false                                            |
 |                         | 'foo' => int 9121240                                           |
 |                         | 43 =>                                                          |
 |                         |    object(stdClass)[1]                                         |
 |                         |      public 'bar' => int 100                                   |
 |                         |                                                                |
 |                         | 44 =>                                                          |
 |                         |    object(stdClass)[2]                                         |
 |_________________________|__45_=>_resource(4,_stream)___________________________________|
 |_____________________$i |int_2176225___________________________________________________|
Error Messages
Record and Delayed Display

 xdebug_start_error_collection()
 xdebug_stop_error_collection()
 xdebug_get_collected_errors()
  <?php
  xdebug_start_error_collection();
  ?>
  <html>
  <body>
  <div id='main'>
  ...
  </div>
  <div id='errors'>
      <?php echo xdebug_get_collected_errors(); ?>
  </div>
  </html>
Pretty Printing Variables

 array(3) { [0]=> NULL [1]=> float(3.141592654) [2]=> array(1) { ["dutch"]=> object(locale)#1 (6) {
 ["lang"]=> string(2) "nl" ["variation"]=> string(2000)
 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc
 dabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc
 dabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc
 dabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc

 array
   0 => null
   1 => float 3.141592654
   2 =>
     array
        'dutch' =>
          object(locale)[1]
            public 'lang' => string 'nl' (length=2)
            public 'variation' => string 'abcdabcdabcdabcdabcdabcda'... (length=2000)
            public 'charsets' =>
              array
                0 => string 'iso-88591' (length=9)
                1 => string 'iso-8859-15' (length=11)
            private 'mb_supported' => boolean false
            protected 'self' =>
              &object(locale)[1]
            protected 'id' => int 1


Options:
 <?php
 ini_set( 'xdebug.var_display_max_data', 25 );
 ini_set( 'xdebug.var_display_max_depth', 4 );
 ini_set( 'xdebug.var_display_max_children', 32 );
 ?>
Turn off in php.ini or .htaccess with:
 xdebug.overload_var_dump = 0
Colours on the Command Line
*new in 2.2*




 xdebug.cli_color=1
Scream

●   PHP's @ operator hides warnings and errors
●   xdebug.scream=1 makes PHP ignore @
Recording headers

●   Xdebug collects all headers being set, implicitly
    and explicitly
●   It's very useful for testing and unit-tests
●   xdebug_get_headers()
 <?php
 session_start();

 setcookie( 'key', 'value', time() + 86400 );

 header( "Status: 403" );

 var_dump( xdebug_get_headers() );
 ?>
Tracing
Function trace

 TRACE START [2010-03-24 11:03:12]
     0.0022     787776   -> {main}() /home/httpd/pres2/show2.php:0
     0.0028     803160     -> require(/home/derick/dev/ezcomponents/trunk/Base/src/
 ezc_bootstrap.php)/home/httpd/pres2/show2.php:2
     0.0029     803552       -> dirname('/home/derick/dev/ezcomponents/trunk/Base/src/
 ezc_bootstrap.php')/home/derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:12
     0.0030     803968       -> explode('/', '/home/derick/dev/ezcomponents/trunk/Base/src')/home/
 derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:13
     0.0031     807352       -> count(array (0 => '', 1 => 'home', 2 => 'derick', 3 => 'dev', 4 =>
 'ezcomponents', 5 => 'trunk', 6 => 'Base', 7 => 'src'))/home/derick/dev/ezcomponents/trunk/Base/src/
 ezc_bootstrap.php:15
     0.0032     807800       -> array_slice(array (0 => '', 1 => 'home', 2 => 'derick', 3 => 'dev', 4
 => 'ezcomponents', 5 => 'trunk', 6 => 'Base', 7 => 'src'), 0, -2)/home/derick/dev/ezcomponents/
 trunk/Base/src/ezc_bootstrap.php:17
     0.0033     808952       -> join('/', array (0 => '', 1 => 'home', 2 => 'derick', 3 => 'dev', 4
 => 'ezcomponents', 5 => 'trunk'))/home/derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:17
     0.0065    1002544       -> require(/home/derick/dev/ezcomponents/trunk/Base/src/base.php)/home/
 derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:18




Some settings:
 xdebug.auto_trace=1
 xdebug.trace_output_dir=/tmp
 xdebug.collect_params=1
 xdebug.collect_return=1
 xdebug.collect_includes=1
 xdebug.collect_assignments=1
Function trace to file
Automatic readable format




  xdebug.auto_trace=1       ; enable tracing
  xdebug.trace_format=1     ; selects computerized format
  xdebug.trace_options=0    ; sets extra option (1 = append)
Function trace
Other functionality

 ●   HTML traces
 ●   Tracing only parts of an application with
     xdebug_start_trace() and xdebug_stop_trace().
 ●   Fetching the trace file name that is being used
     with xdebug_get_tracefile_name().
 ●   Changing how much data is shown with
     xdebug.var_display_max_children,
     xdebug.var_display_max_data and
     xdebug.var_display_max_depth.
demo
Swatting Bugs
Live Debugging

● DBGp, common Debugging protocol
● Cross-language: PHP, Python, Perl...


Clients:
● Eclipse/PDT (Java based — free)

● Komodo (Linux, Windows, Mac — commercial)

● MacGDBp (free)

● Netbeans (Java-based — free)

● PHPStorm (Java-based — commercial)

● Zend Studio for Eclipse (Eclipse-based —


  commercial)
● Stand-alone client (Linux (for now)):

● (and many others: )
Activating the Remote Debugger
php.ini settings:
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
php.ini settings:
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_connect_back=1
On the shell:
export XDEBUG_CONFIG="idekey=xdebugrocks"
With a browser:
http://pres/show.php?
XDEBUG_SESSION_START=xdebugrocks
http://pres/show.php?XDEBUG_SESSION_STOP=1
With browser extensions:
easy Xdebug (FireFox), Xdebug Helper (Chrome), Xdebug
Toggler for Safari, Xdebug launcher for Opera:
Debugging Connections
Single-user
Debugging Connections
Multi-user
Xdebug confoo11
Xdebug confoo11
demo
Profiling
Profiling
KCacheGrind's Flat Profile and Call List




  xdebug.profiler_enable=1          ; enable profiler
  xdebug.profiler_output_dir=/tmp    ; output directory
  xdebug.profiler_output_name=cachegrind.out.%p
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
Xdebug

●   It's Open Source and free (as in "free beer")
●   Working on Xdebug takes up a lot of spare time
●   I don't have a lot of spare time
Resources




 ●   Xdebug site: http://xdebug.org
 ●   Xdebug documentation:
     http://xdebug.org/docs.php
 ●   DBGp specification: http://xdebug.org/docs-
     dbgp.php
 ●   Rate this talk! :-:joindin:-:
 ●   If you like Xdebug: http://xdebug.org/donate.php
 ●   These slides: http://derickrethans.nl/talks.html

More Related Content

PDF
Pim Elshoff "Technically DDD"
PDF
Type safe embedded domain-specific languages
PPTX
The zen of async: Best practices for best performance
PPTX
Let's write secure Drupal code! - DrupalCamp London 2019
PDF
Declarative Internal DSLs in Lua: A Game Changing Experience
PPTX
Dartprogramming
PPT
Design Patterns
PDF
Python dictionary : past, present, future
Pim Elshoff "Technically DDD"
Type safe embedded domain-specific languages
The zen of async: Best practices for best performance
Let's write secure Drupal code! - DrupalCamp London 2019
Declarative Internal DSLs in Lua: A Game Changing Experience
Dartprogramming
Design Patterns
Python dictionary : past, present, future

What's hot (20)

PDF
Entity api
PDF
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
PDF
Error based blind sqli
PPT
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
PDF
Dependency Injection
PDF
Your code sucks, let's fix it - DPC UnCon
PDF
The Etsy Shard Architecture: Starts With S and Ends With Hard
PDF
Dig Deeper into WordPress - WD Meetup Cairo
PPT
Php Security By Mugdha And Anish
PPTX
PHP Session - Mcq ppt
PDF
Dependency injection in PHP 5.3/5.4
PPTX
Adding Dependency Injection to Legacy Applications
PDF
Drupal Field API. Practical usage
PDF
SOLID Ruby SOLID Rails
PDF
Asynchronous JS in Odoo
PDF
Data Validation models
PPTX
Building High Perf Web Apps - IE8 Firestarter
PDF
Dependency Injection with PHP and PHP 5.3
PDF
Dependency injection - phpday 2010
PPTX
HCE tutorial
Entity api
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Error based blind sqli
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Dependency Injection
Your code sucks, let's fix it - DPC UnCon
The Etsy Shard Architecture: Starts With S and Ends With Hard
Dig Deeper into WordPress - WD Meetup Cairo
Php Security By Mugdha And Anish
PHP Session - Mcq ppt
Dependency injection in PHP 5.3/5.4
Adding Dependency Injection to Legacy Applications
Drupal Field API. Practical usage
SOLID Ruby SOLID Rails
Asynchronous JS in Odoo
Data Validation models
Building High Perf Web Apps - IE8 Firestarter
Dependency Injection with PHP and PHP 5.3
Dependency injection - phpday 2010
HCE tutorial
Ad

Viewers also liked (20)

PDF
Clipagem tarumã setembro 2010
PDF
Livestock and Land
PDF
cPanel User Manual
PDF
C lipagem tarumã maio 2010
PPT
Introduction Php
PDF
Technote Index Map Help
PPT
いちばん簡単なconcrete5テーマ
PDF
Developing Your Ultimate Package
PDF
C lipagem tarumã outubro 2010
PPTX
La evolución de los medios de información
PDF
password (facebook)
PDF
concrete5 5.7でテーマ作ってみよう 超初級編
PDF
Real Developer Tools for WordPress by Stefan Didak
PDF
TYPO3 CMS 7.1 - Die Neuerungen - pluswerk
PPT
A portrait chapter_1
PPTX
Google Dorks
PDF
TYPO3 CMS 6.2 LTS - Die Neuerungen
PPTX
Sql Injection and Entity Frameworks
PPTX
Google Dorks and SQL Injection
Clipagem tarumã setembro 2010
Livestock and Land
cPanel User Manual
C lipagem tarumã maio 2010
Introduction Php
Technote Index Map Help
いちばん簡単なconcrete5テーマ
Developing Your Ultimate Package
C lipagem tarumã outubro 2010
La evolución de los medios de información
password (facebook)
concrete5 5.7でテーマ作ってみよう 超初級編
Real Developer Tools for WordPress by Stefan Didak
TYPO3 CMS 7.1 - Die Neuerungen - pluswerk
A portrait chapter_1
Google Dorks
TYPO3 CMS 6.2 LTS - Die Neuerungen
Sql Injection and Entity Frameworks
Google Dorks and SQL Injection
Ad

Similar to Xdebug confoo11 (20)

KEY
Zend Framework Study@Tokyo #2
PDF
Advanced Php - Macq Electronique 2010
PPTX
Meet Magento Belarus debug Pavel Novitsky (eng)
PDF
Hacking ansible
PDF
Your Entity, Your Code
PDF
Your Entity, Your Code
PDF
Building Testable PHP Applications
PDF
How to fake_properly
PDF
Why GC is eating all my CPU?
PDF
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
PDF
Zend Framework 2 - Basic Components
PDF
From mysql to MongoDB(MongoDB2011北京交流会)
PPT
Introducing PHP Data Objects
PDF
Building source code level profiler for C++.pdf
PDF
Web internship Yii Framework
PDF
.NET 7 Performance Improvements_10_03_2023.pdf
PDF
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
PDF
Extending MariaDB with user-defined functions
PDF
Zeronights 2016 - Automating iOS blackbox security scanning
Zend Framework Study@Tokyo #2
Advanced Php - Macq Electronique 2010
Meet Magento Belarus debug Pavel Novitsky (eng)
Hacking ansible
Your Entity, Your Code
Your Entity, Your Code
Building Testable PHP Applications
How to fake_properly
Why GC is eating all my CPU?
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Zend Framework 2 - Basic Components
From mysql to MongoDB(MongoDB2011北京交流会)
Introducing PHP Data Objects
Building source code level profiler for C++.pdf
Web internship Yii Framework
.NET 7 Performance Improvements_10_03_2023.pdf
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Extending MariaDB with user-defined functions
Zeronights 2016 - Automating iOS blackbox security scanning

More from Bachkoutou Toutou (14)

PDF
Making php see, confoo 2011
PDF
Sean coates fifty things and tricks, confoo 2011
PDF
hacking your website with vega, confoo2011
PDF
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
PDF
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
PDF
Zend Framework 2, What's new, Confoo 2011
PDF
Connecting web Applications with Desktop, confoo 2011
PDF
Connecting Web Application and Desktop, confoo 2011, qafoo
PDF
99 problems but the search aint one, confoo 2011, andrei zmievski
PDF
Php Inside - confoo 2011 - Derick Rethans
PDF
WebShell - confoo 2011 - sean coates
PDF
Stress Free Deployment - Confoo 2011
PDF
Apc Memcached Confoo 2011
PDF
Confoo 2011 - Advanced OO Patterns
Making php see, confoo 2011
Sean coates fifty things and tricks, confoo 2011
hacking your website with vega, confoo2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
Connecting web Applications with Desktop, confoo 2011
Connecting Web Application and Desktop, confoo 2011, qafoo
99 problems but the search aint one, confoo 2011, andrei zmievski
Php Inside - confoo 2011 - Derick Rethans
WebShell - confoo 2011 - sean coates
Stress Free Deployment - Confoo 2011
Apc Memcached Confoo 2011
Confoo 2011 - Advanced OO Patterns

Xdebug confoo11

  • 1. Welcome! ConFoo Montréal, Canada - March 9th, 2011 Derick Rethans - derick@derickrethans.nl - twitter: @derickr http://derickrethans.nl/talks.html http://joind.in/2783
  • 2. About Me Derick Rethans ● Dutchman living in London ● PHP development ● Author of the mcrypt, input_filter, dbus, translit and date/time extensions ● Author of Xdebug ● Contributor to the Apache Zeta Components Incubator project (formerly eZ Components) ● Freelancer doing PHP (internals) development
  • 5. Error Messages Warning: DOMDocument::load() [domdocument.load]: Document is empty in /home/httpd/presentations, line: 1 in /home/httpd/pres2/show2.php on line 165 _________________________________________________________________________________________________ |( ! ) Warning: DOMDocument::load() [domdocument.load]: Document is empty in /home/httpd/ | |presentations,_line:_1_in_/home/httpd/pres2/show2.php_on_line_165________________________________| |Call_Stack_______________________________________________________________________________________| |#|Time__|Memory_|Function_______________________________________________________|Location________| |1|0.0013|_787720|{main}(_)______________________________________________________|../show2.php:0__| |2|0.0102|1398552|Presentation->display(_$slideNr_=_NULL_)_______________________|../show2.php:114| |3|0.0103|1400336|DOMDocument->load( &apos;/home/httpd/pres2/presentations/&apos;|../show2.php:165| |_|______|_______|)______________________________________________________________|________________| ● xdebug.collect_include=? ● xdebug.var_display_max_children=? xdebug.var_display_max_data=? xdebug.var_display_max_depth=? ● xdebug.file_link_format=? xdebug.file_link_format=gvim://f@l xdebug.file_link_format=txmt://open/?url=file://f&line=l xdebug.file_link_format=???://f?l Windows: http://forums.netbeans.org/topic20597.html#85639 Linux: http://xdebug.org/docs/stack_trace#file_link_format
  • 6. Error Messages Pimped-Up with CSS ________________________________________________________________________________________ |( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/| |xdebug/docs/stack.php_on_line_66________________________________________________________| |Call_Stack______________________________________________________________________________| |#|Time___________________|Memory|Function_|Location_____________________________________| |1|____________0.0004_____|691504|{main}(_)|../stack.php:0_______________________________| |2|____________0.0006_____|699472|foo(_)___|../stack.php:82______________________________| |Dump_$_SERVER___________________________________________________________________________| |$_SERVER['REQUEST_URI'] |string_'/test/xdebug/docs/stack.php?level=7'_(length=35)______| |Variables_in_local_scope_(#2)___________________________________________________________| | $a |array (size=5) | | | | | | 42 => boolean false | | | 'foo' => int 9121240 | | | 43 => | | | object(stdClass)[1] | | | public 'bar' => int 100 | | | | | | 44 => | | | object(stdClass)[2] | |_________________________|__45_=>_resource(4,_stream)___________________________________| |_____________________$i |int_2176225___________________________________________________|
  • 7. Error Messages Record and Delayed Display xdebug_start_error_collection() xdebug_stop_error_collection() xdebug_get_collected_errors() <?php xdebug_start_error_collection(); ?> <html> <body> <div id='main'> ... </div> <div id='errors'> <?php echo xdebug_get_collected_errors(); ?> </div> </html>
  • 8. Pretty Printing Variables array(3) { [0]=> NULL [1]=> float(3.141592654) [2]=> array(1) { ["dutch"]=> object(locale)#1 (6) { ["lang"]=> string(2) "nl" ["variation"]=> string(2000) "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc dabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc dabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc dabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc array 0 => null 1 => float 3.141592654 2 => array 'dutch' => object(locale)[1] public 'lang' => string 'nl' (length=2) public 'variation' => string 'abcdabcdabcdabcdabcdabcda'... (length=2000) public 'charsets' => array 0 => string 'iso-88591' (length=9) 1 => string 'iso-8859-15' (length=11) private 'mb_supported' => boolean false protected 'self' => &object(locale)[1] protected 'id' => int 1 Options: <?php ini_set( 'xdebug.var_display_max_data', 25 ); ini_set( 'xdebug.var_display_max_depth', 4 ); ini_set( 'xdebug.var_display_max_children', 32 ); ?> Turn off in php.ini or .htaccess with: xdebug.overload_var_dump = 0
  • 9. Colours on the Command Line *new in 2.2* xdebug.cli_color=1
  • 10. Scream ● PHP's @ operator hides warnings and errors ● xdebug.scream=1 makes PHP ignore @
  • 11. Recording headers ● Xdebug collects all headers being set, implicitly and explicitly ● It's very useful for testing and unit-tests ● xdebug_get_headers() <?php session_start(); setcookie( 'key', 'value', time() + 86400 ); header( "Status: 403" ); var_dump( xdebug_get_headers() ); ?>
  • 13. Function trace TRACE START [2010-03-24 11:03:12]     0.0022     787776   -> {main}() /home/httpd/pres2/show2.php:0     0.0028     803160     -> require(/home/derick/dev/ezcomponents/trunk/Base/src/ ezc_bootstrap.php)/home/httpd/pres2/show2.php:2     0.0029     803552       -> dirname('/home/derick/dev/ezcomponents/trunk/Base/src/ ezc_bootstrap.php')/home/derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:12     0.0030     803968       -> explode('/', '/home/derick/dev/ezcomponents/trunk/Base/src')/home/ derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:13     0.0031     807352       -> count(array (0 => '', 1 => 'home', 2 => 'derick', 3 => 'dev', 4 => 'ezcomponents', 5 => 'trunk', 6 => 'Base', 7 => 'src'))/home/derick/dev/ezcomponents/trunk/Base/src/ ezc_bootstrap.php:15     0.0032     807800       -> array_slice(array (0 => '', 1 => 'home', 2 => 'derick', 3 => 'dev', 4 => 'ezcomponents', 5 => 'trunk', 6 => 'Base', 7 => 'src'), 0, -2)/home/derick/dev/ezcomponents/ trunk/Base/src/ezc_bootstrap.php:17     0.0033     808952       -> join('/', array (0 => '', 1 => 'home', 2 => 'derick', 3 => 'dev', 4 => 'ezcomponents', 5 => 'trunk'))/home/derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:17     0.0065    1002544       -> require(/home/derick/dev/ezcomponents/trunk/Base/src/base.php)/home/ derick/dev/ezcomponents/trunk/Base/src/ezc_bootstrap.php:18 Some settings: xdebug.auto_trace=1 xdebug.trace_output_dir=/tmp xdebug.collect_params=1 xdebug.collect_return=1 xdebug.collect_includes=1 xdebug.collect_assignments=1
  • 14. Function trace to file Automatic readable format xdebug.auto_trace=1 ; enable tracing xdebug.trace_format=1 ; selects computerized format xdebug.trace_options=0 ; sets extra option (1 = append)
  • 15. Function trace Other functionality ● HTML traces ● Tracing only parts of an application with xdebug_start_trace() and xdebug_stop_trace(). ● Fetching the trace file name that is being used with xdebug_get_tracefile_name(). ● Changing how much data is shown with xdebug.var_display_max_children, xdebug.var_display_max_data and xdebug.var_display_max_depth.
  • 16. demo
  • 18. Live Debugging ● DBGp, common Debugging protocol ● Cross-language: PHP, Python, Perl... Clients: ● Eclipse/PDT (Java based — free) ● Komodo (Linux, Windows, Mac — commercial) ● MacGDBp (free) ● Netbeans (Java-based — free) ● PHPStorm (Java-based — commercial) ● Zend Studio for Eclipse (Eclipse-based — commercial) ● Stand-alone client (Linux (for now)): ● (and many others: )
  • 19. Activating the Remote Debugger php.ini settings: xdebug.remote_enable=1 xdebug.remote_host=localhost xdebug.remote_port=9000 php.ini settings: xdebug.remote_enable=1 xdebug.remote_host=localhost xdebug.remote_port=9000 xdebug.remote_connect_back=1 On the shell: export XDEBUG_CONFIG="idekey=xdebugrocks" With a browser: http://pres/show.php? XDEBUG_SESSION_START=xdebugrocks http://pres/show.php?XDEBUG_SESSION_STOP=1 With browser extensions: easy Xdebug (FireFox), Xdebug Helper (Chrome), Xdebug Toggler for Safari, Xdebug launcher for Opera:
  • 24. demo
  • 26. Profiling KCacheGrind's Flat Profile and Call List xdebug.profiler_enable=1 ; enable profiler xdebug.profiler_output_dir=/tmp ; output directory xdebug.profiler_output_name=cachegrind.out.%p
  • 27. 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
  • 28. demo
  • 29. Xdebug ● It's Open Source and free (as in "free beer") ● Working on Xdebug takes up a lot of spare time ● I don't have a lot of spare time
  • 30. Resources ● Xdebug site: http://xdebug.org ● Xdebug documentation: http://xdebug.org/docs.php ● DBGp specification: http://xdebug.org/docs- dbgp.php ● Rate this talk! :-:joindin:-: ● If you like Xdebug: http://xdebug.org/donate.php ● These slides: http://derickrethans.nl/talks.html