Chapter 16. Optimization and Debugging

WHAT'S IN THIS CHAPTER?

  • Using PHP back-traces

  • Learning what you need to review SQL performance

  • Understanding how to review SQL statements with EXPLAIN

  • Learning about different index optimizations

No matter how well thought out or planned an application is, there are always problems and they can creep up at any moment. Ranging from performance issues to functionality flaws, you may feel it's completely impossible to find and diagnose them.

Fortunately PHP and MySQL have tools to help deal with such situations. This chapter covers the tools of the trade and best practices for debugging and optimizing PHP and MySQL. It starts with advanced PHP debugging — including ways to find hidden performance bottlenecks — and then gets into the details on how to make slow queries run fast.

DEBUGGING PHP

For simple applications it is possible to get away with just basic debugging techniques. Some of the most common are using print_r() to recursively display the contents of an array or class or var_dump() when a little bit more information is needed.

For more complex applications, basic debugging is simply not enough. It becomes necessary to closely inspect the state of the application. This section reviews methods for inspecting state, injecting code into the application at run time, and profiling the application to achieve performance boosts.

Creating Stack Traces

One of the most basic forms of PHP debugging is the debug back-trace, which produces an associative array ...

Get Expert PHP and MySQL® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.