Skip to main content

Blog Post

Advanced Debugging Techniques for PHP

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.

 

Headshot

Meet team member, Edward Chan

Edward brings four years of Drupal and full-stack experience to his role as a Developer at Mediacurrent. He has experience in all tiers in the Drupal stack- from front-end theming, to custom module development, to performance/scalability and migrations. One of his main interests right now is to dive deeper into Drupal 8 and headless Drupal architecture using modern frameworks and libraries. Edward is also an active attendee at regional Drupal camps, DrupalCon, and other technical meetups.

Edward started his Drupal career at The Gilder Lehrman Institute of American History, where he was first exposed to Drupal. During his time there, he was part of a 2-person tech team that helped enhance and scale the website which  generated 100% increase in traffic year over year. He then joined NorthPoint Digital as a consultant and implemented Drupal solutions based on client needs. During his tenure there, he gained immense experience with custom module development in an agile environment, and even had the chance to contribute his first patch to a contrib module (Social Media Aggregator)! He also further developed his skills by diving into some modern technologies such as React and Node.js to work with Drupal data.

Born and raised in New York City, Edward is accustomed to the fast-paced lifestyle and enjoys roaming around NYC searching for the next best cup of coffee, finding the next restaurant serving exotic foods, as well as attending Knicks games.

Learn more about Edward >

Related Insights