advanced debugging techniques (php)

35
Advanced debugging techniques Patrick Allaert phpDay Verona 2015, Italy

Upload: patrick-allaert

Post on 19-Jul-2015

555 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Advanced debugging techniques (PHP)

Advanced debuggingtechniques

Patrick Allaert

phpDay Verona 2015, Italy

Page 2: Advanced debugging techniques (PHP)

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/

Page 3: Advanced debugging techniques (PHP)

Debugging what?

● PHP execution:● XDebug● PHPdbg● phptrace

● System● system calls: strace● library calls: ltrace● FS notifications: inotify

● Networking● Wireshark● MySQL Proxy

Page 4: Advanced debugging techniques (PHP)

Before we start...

Page 5: Advanced debugging techniques (PHP)

The most powerful debugging technique is...

Page 6: Advanced debugging techniques (PHP)

The most powerful debugging technique is...

Rubber duck debugging!

Page 7: Advanced debugging techniques (PHP)

Rubber duck debugging!

● You have an issue!

Page 8: Advanced debugging techniques (PHP)

Rubber duck debugging!

● You have an issue!● Decide to bring it on Stack Overflow

Page 9: Advanced debugging techniques (PHP)

Rubber duck debugging!

● You have an issue!● Decide to bring it on Stack Overflow● Write down your question

Page 10: Advanced debugging techniques (PHP)

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

Page 11: Advanced debugging techniques (PHP)

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

Page 12: Advanced debugging techniques (PHP)

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

Page 13: Advanced debugging techniques (PHP)

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

Page 14: Advanced debugging techniques (PHP)

Rubber duck debugging!

Page 15: Advanced debugging techniques (PHP)

Rubber duck debugging!

Page 16: Advanced debugging techniques (PHP)

Rubber duck debugging!

Page 17: Advanced debugging techniques (PHP)

Rubber duck debugging!

Page 18: Advanced debugging techniques (PHP)

Rubber duck debugging!

Page 19: Advanced debugging techniques (PHP)

Rubber duck debugging!

Page 20: Advanced debugging techniques (PHP)

Debugging PHP

Page 21: Advanced debugging techniques (PHP)

PHPdbg

● Super powerful and native PHP debugger, included by default starting PHP 5.6

Page 22: Advanced debugging techniques (PHP)
Page 23: Advanced debugging techniques (PHP)
Page 24: Advanced debugging techniques (PHP)

PHPdbg: List source code

Page 25: Advanced debugging techniques (PHP)

PHPdbg: List opcodes

Page 26: Advanced debugging techniques (PHP)

PHPdbg: debugging

Page 27: Advanced debugging techniques (PHP)

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]

Page 28: Advanced debugging techniques (PHP)

phptrace

● First version of phptrace released YESTERDAY!

https://pecl.php.net/package/trace

Page 29: Advanced debugging techniques (PHP)

System debugging

Page 30: Advanced debugging techniques (PHP)

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.

Page 31: Advanced debugging techniques (PHP)

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.

Page 32: Advanced debugging techniques (PHP)

Inotify

● Native Linux FS notification mechanism

Page 33: Advanced debugging techniques (PHP)

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

Page 34: Advanced debugging techniques (PHP)

Wireshark

● Catches network traffic and analyze it● Hundreds of protocols

Page 35: Advanced debugging techniques (PHP)

Thanks

Don't forget to rate this talk on https://joind.in/14562

Stay in touch!@patrick_allaert

[email protected]