advanced debugging techniques (php)
TRANSCRIPT
Advanced debuggingtechniques
Patrick Allaert
phpDay Verona 2015, Italy
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● [email protected]● http://github.com/patrickallaert/● http://patrickallaert.blogspot.com/
Debugging what?
● PHP execution:● XDebug● PHPdbg● phptrace
● System● system calls: strace● library calls: ltrace● FS notifications: inotify
● Networking● Wireshark● MySQL Proxy
Before we start...
The most powerful debugging technique is...
The most powerful debugging technique is...
Rubber duck debugging!
Rubber duck debugging!
● You have an issue!
Rubber duck debugging!
● You have an issue!● Decide to bring it on Stack Overflow
Rubber duck debugging!
● You have an issue!● Decide to bring it on Stack Overflow● Write down your question
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
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
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
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
Rubber duck debugging!
Rubber duck debugging!
Rubber duck debugging!
Rubber duck debugging!
Rubber duck debugging!
Rubber duck debugging!
Debugging PHP
PHPdbg
● Super powerful and native PHP debugger, included by default starting PHP 5.6
PHPdbg: List source code
PHPdbg: List opcodes
PHPdbg: debugging
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]
phptrace
● First version of phptrace released YESTERDAY!
https://pecl.php.net/package/trace
System debugging
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.
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.
Inotify
● Native Linux FS notification mechanism
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
Wireshark
● Catches network traffic and analyze it● Hundreds of protocols
Thanks
Don't forget to rate this talk on https://joind.in/14562
Stay in touch!@patrick_allaert