Debugging is an essential part of any developer’s development process. Most of us are familiar with the Xdebug debugger, but there are also a handful of other debugging tools we can utilize in our workflows.

During DrupalCon Baltimore, there was a session on “Advanced Debugging Techniques for PHP” given by Patrick Allaert. This was one of the more popular sessions and had a great turnout in a packed and overflowed room. In this post, I will be giving a glimpse of the main points and takeaways I got out of attending this session.

This session opened with the “Rubber duck” debugging method - which involves a programmer explaining code to a rubber duck. As a result of explaining the problem with context to the duck, it forces the programmer to think about the problem as a whole in a bigger perspective - during which the programmer usually stumbles upon the solution or another approach to finding one.

This technique can be helpful for some, but as developers, we love learning about the new tools we can add to our arsenal.
 

Below is a list of debugging and monitoring tools brought up in the session:

phpdbg
This powerful native interactive debugger comes by default with PHP 5.6 It is a CLI tool that can allow the programmer to debug using breakpoints to step through code. It also provides easy access to PHP with built-in eval().

phptrace
This tracing and troubleshooting tool can trace running PHP processes, function calls, and request information during run-time. It can be installed as a PHP extension or a CLI tool.

strace
This is a diagnostics and debugging tool that is useful in debugging at a system level. It is used to trace any system calls and signals performed by a program and is invaluable in troubleshooting programs in which the source is not readily available.

ltrace
This is a library call tracer tool used to trace any libraries in a program. Dynamic library calls made by an executed process are intercepted and recorded.

inotify
This API provides a native Linux filesystem notification mechanism that can be used to monitor events for individual files or entire directories.

MySQL Proxy
This is a program that sits in between your client and MySQL server(s) to monitor, analyze, or even transform the communication for real-time SQL debugging and troubleshooting. It also allows for custom configuration through Lua scripting -- examples of such is provided by Patrick.

Nethogs
This tool is similar to the top command but used for monitoring network bandwidth. It groups bandwidth by process to allow for identifying processes that are exhausting bandwidth.

Wireshark
This is a popular general purpose, open-source network protocol analyzer used to monitor and analyze network traffic. It is similar to tcpdump and provides a user interface with sorting and filtering capabilities. Additionally, Wireshark has great support for custom dissectors for analyzing custom protocols.

It was definitely refreshing to be exposed to a strong set of debugging tools and techniques that can be incorporated into any developer’s workflow. For me, the best part about this session was that Patrick covered debugging/monitoring tools across all levels - from low-level PHP processes to filesystems, libraries, and network traffic. These tools are invaluable to any developer looking to optimize their debugging process and become even more valuable as projects become more complex.

The DrupalCon session recording can be found at
https://events.drupal.org/baltimore2017/sessions/advanced-debugging-techniques.