Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Advanced debugging techniques (PHP)

2,848 views

Published on

Step-by-step debugging with Xdebug is no secret for you? Perfect then, because we won’t talk about it. We will rather see tools that let you know what’s really happening in your PHP code, like the recent phpdbg debugger and phptrace, process tracing tools like: strace, ltrace, the Linux inotify mechanism, tcpdump/wireshark for network analysis,…

Published in: Technology

Advanced debugging techniques (PHP)

  1. 1. Advanced debugging techniques Patrick Allaert phpDay Verona 2015, Italy
  2. 2. About me ● Patrick Allaert ● Founder of Libereco and co-founder of catchy.io ● Playing with PHP/Linux for +15 years ● eZ Publish core developer ● Author of the APM PHP extension ● @patrick_allaert ● patrickallaert@php.net ● http://github.com/patrickallaert/ ● http://patrickallaert.blogspot.com/
  3. 3. Debugging what? ● PHP execution: ● XDebug ● PHPdbg ● phptrace ● System ● system calls: strace ● library calls: ltrace ● FS notifications: inotify ● Networking ● Wireshark ● MySQL Proxy
  4. 4. Before we start...
  5. 5. The most powerful debugging technique is...
  6. 6. The most powerful debugging technique is... Rubber duck debugging!
  7. 7. Rubber duck debugging! ● You have an issue!
  8. 8. Rubber duck debugging! ● You have an issue! ● Decide to bring it on Stack Overflow
  9. 9. Rubber duck debugging! ● You have an issue! ● Decide to bring it on Stack Overflow ● Write down your question
  10. 10. Rubber duck debugging! ● You have an issue! ● Decide to bring it on Stack Overflow ● Write down your question ● Realize that it doesn't make any sense
  11. 11. Rubber duck debugging! ● You have an issue! ● Decide to bring it on Stack Overflow ● Write down your question ● Realize that it doesn't make any sense ● Rethink how to ask it with enough information
  12. 12. Rubber duck debugging! ● You have an issue! ● Decide to bring it on Stack Overflow ● Write down your question ● Realize that it doesn't make any sense ● Rethink how to ask it with enough information ● Realize that you are attacking the problem from a wrong perspective
  13. 13. Rubber duck debugging! ● You have an issue! ● Decide to bring it on Stack Overflow ● Write down your question ● Realize that it doesn't make any sense ● Rethink how to ask it with enough information ● Realize that you are attacking the problem from a wrong perspective ● Start again from scratch and find your solution
  14. 14. Rubber duck debugging!
  15. 15. Rubber duck debugging!
  16. 16. Rubber duck debugging!
  17. 17. Rubber duck debugging!
  18. 18. Rubber duck debugging!
  19. 19. Rubber duck debugging!
  20. 20. Debugging PHP
  21. 21. PHPdbg ● Super powerful and native PHP debugger, included by default starting PHP 5.6
  22. 22. PHPdbg: List source code
  23. 23. PHPdbg: List opcodes
  24. 24. PHPdbg: debugging
  25. 25. phptrace ● Low overhead tracing tool composed of a PHP extension and a command line tool php -r 'for ($i = 0; $i < 100; $i++) usleep(10000);' & ./phptrace -p $! 1431763911.194806 usleep(10000) at [Command line code:1] 1431763911.204932 usleep => NULL wt: 0.010126 ct: 0.000000 1431763911.204950 usleep(10000) at [Command line code:1] 1431763911.215045 usleep => NULL wt: 0.010095 ct: 0.000000 1431763911.215056 usleep(10000) at [Command line code:1] 1431763911.225177 usleep => NULL wt: 0.010121 ct: 0.000000 1431763911.225192 usleep(10000) at [Command line code:1]
  26. 26. phptrace ● First version of phptrace released YESTERDAY! https://pecl.php.net/package/trace
  27. 27. System debugging
  28. 28. strace ● Let's you trace any system calls done by a program ● $ strace <program to run> ● $ strace -p <pid> [-f] ● Use -e <category> to filter the type of syscall to catch. ● Use -c for a summary of the system calls performed.
  29. 29. ltrace ● Let's you trace any library call ● Watch out, this might be very verbose! ● $ ltrace <program to run> ● $ ltrace -p <pid> [-f] ● Use -l <library> to filter on a specific library.
  30. 30. Inotify ● Native Linux FS notification mechanism
  31. 31. MySQL Proxy ● Sits between a client and a server and let's you do what you want thanks to lua scripting. ● Examples: ● Printing: – all queries – the ones not using an index – the slow ones ● Graphing the most frequent queries / used tables ● Simulate a heavy loaded (read:“slow”) DB ● https://github.com/patrickallaert/MySQL-Proxy-scripts-for-devs
  32. 32. Wireshark ● Catches network traffic and analyze it ● Hundreds of protocols
  33. 33. Thanks Don't forget to rate this talk on https://joind.in/14562 Stay in touch! @patrick_allaert patrickallaert@php.net

×