O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.


An overview of xdebug, the PHP debugging tool

  • Entre para ver os comentários

  • Seja a primeira pessoa a gostar disto


  1. 1. xdebug Shedding light on your code.
  2. 2. Who Is This Guy? Bryce Embry Application Developer at Vanderbilt University Medical Center Devoted user of Opera web browser Ambivalent user of Windows Desktop Handyman, cook, hobbyist musician, husband, & father
  3. 3. In this session… ▪ What is xdebug? ▪ Getting Started ▪ Tracing ▪ Profiling ▪ Debugging ▪ Debug Demo
  4. 4. What is xdebug
  5. 5. Tracing List all the functions being called, and who is calling them.
  6. 6. Profiling See how long each of those function calls takes
  7. 7. Debugging Pause code execution See variable values Walk through code one step at a time
  8. 8. Code Coverage Identify which lines of a script have been executed during a request. This feature is used by other programs to create test coverage reports
  9. 9. Enhanced PHP Error Messages Without xdebug With xdebug
  10. 10. Getting Started
  11. 11. Two Part Install ▪ Server: – Install xdebug extension to PHP – Configure php.ini – Restart web server ▪ Client – Install browser extension
  12. 12. Server: Install Xdebug http://xdebug.org/wizard.php
  13. 13. Server: Configure php php.ini phpinfo()
  14. 14. Client: URL Triggers To trigger xdebug, need to use a cookie or add parameters to the URL. Doing this by hand violates the programming principle, “Work hard to be lazy”.
  15. 15. Client: Bookmarklets PHPStorm has a site to create “bookmarklets” to add trigger parameters to your URL. https://www.jetbrains.com/phpstorm/marklets/
  16. 16. Client: Browser Extension Firefox has an extension available.
  17. 17. Client: Browser Extension Chrome has a better extension, especially if you look at the contributors.
  18. 18. Tracing
  19. 19. Running a trace 1. In browser, activate trace 2. Load web page 3. On server, find trace file 4. Review trace file
  20. 20. Trace Sample foreach loop vs array_map
  21. 21. Sample Configurations phpinfo () php.i ni https://xdebug.org/docs/execution_trace
  22. 22. Configuration Options trace_enable_trigger Turn “on” to allow traces trace_enable_trigger_valu e Sets a passcode that must be passed by browser to start a trace trace_format Sets the output format for a trace as human-readable, machine readable, or HTML trace_options Turn “on” to have trace data appended to a file instead of creating new file. trace_output_dir Sets directory where trace file will be saved. Make sure this directory is readable by the PHP process (ie Apache) If using HTML output, set this as a web-accessible directory trace_output_name Sets name for trace file. The extension “.xt” will be appended by default. Can include variables such as: %t = timestamp %R = $_SERVER[‘REQUEST_URI’]
  23. 23. Nifty Tool: xdebug-trace-tree https://github.com/splitbrain/xdebug-trace-tree
  24. 24. Profiling
  25. 25. Running a profile 1. In browser, activate profile 2. Load web page 3. Look for new cachegrind file on server. 4. Open in IDE or KcacheGrind
  26. 26. Sample Profiles kCacheGrin d PHPStorm
  27. 27. Sample Configurations phpinfo () php.ini
  28. 28. Configuration Options profiler_append Turn “on” to have data appended to existing file instead of creating a new file. profiler_enable Turn “on” if you want constant profiling. (Hint: You don’t.) profiler_enable_trigger Turn “on” to allow profiling to be activated by a browser trigger profiler_enable_trigger_valu e Sets a passcode that must be passed by browser to start a profile profiler_output_dir Sets directory where profile file will be saved. Make sure this directory is readable by the PHP process (ie Apache) profiler_output_name Sets name for profile file. Can include variables such as: %t = timestamp %s = script name
  29. 29. Nifty Tool: kcachegrind https://kcachegrind.github.io/html/Home.html
  30. 30. Debugging
  31. 31. How debugging works Web server IDE & Browser http request / 80 dbgp / 9000 http response / 80
  32. 32. Debugging with xdebug 1. Set pause point in code 2. Turn on listening in IDE 3. Enable debug in browser 5. Walk through code in the IDE as it is executed 4. Load page in browser
  33. 33. Sample Configurations phpinfo () php.ini
  34. 34. Configuration Options remote_enable Turn “on” to enable debugging Remote_host Set the host name or IP address of the debugging client computer. Can only have one value, so good way to lock down xdebug to only one user. Remote_connect_back Turn “on” to ignore the remote_host setting and connect back to any xdebug client. Useful if multiple developers are running from same debug server. Remote_port Set the port xdebug uses for communication. Default is 9000. Remote_mode Set to “req” to connect to debug client when code begins. Set to “jit” to connect to debut client only on failure.
  35. 35. Tip: Map your code If you have two copies of code (local and server), make sure they are mapped in the IDE and in- sync. Otherwise, xdebug will lie to you.
  36. 36. Tip: Debugging is one-way Once you’ve passed a point in code, you can’t go back.
  37. 37. Tip: Navigating Code Step over Step into Composer/Autoload/Classloader Symfony/Component/Routing Step Out
  38. 38. Debug Demo
  39. 39. To show in demo ▪ Start / stop debug process ▪ Stepping through code ▪ Conditional break points ▪ Modifying values in running code
  40. 40. Questions?
  41. 41. End Notes Resources: xdebug.org www.thornview.com Presentation by: Bryce.Embry@vanderbilt.edu Fonts: Sketchy - http://dl.dafont.com/dl/?f=sketchy DJB Chalk It Up - http://dl.dafont.com/dl/?f=djb_chalk_it_up Source Sans Pro - http://www.fontsquirrel.com/fonts/source-sans-pro