Chapter 12

Optimizing PHP

WHAT’S IN THIS CHAPTER?

  • Using opcode caching to speed up execution
  • Handling PHP sessions
  • Profiling bottlenecks with xhprof
  • Optimizing your PHP code

With so many different programming languages and development frameworks in use on the modern web, it would be impossible to even attempt to do them justice trying to completely cover them in a single book. Since PHP has easily become the most popular web scripting language in UNIX/Linux environments, it’s worth delving a bit deeper into how the language affects performance.

The downside to the popularity of back-end scripting is, of course, higher performance overheads. Although PHP scripts are typically fairly lightweight, they are still a lot slower to serve up than static HTML documents. In the case of heavier scripts, there can be a significant performance hit — both for the client (in the form of higher latency in requests), and for the server (in the form of higher resource usage, and a lower limit on the number of concurrent requests). In this chapter, you learn about a variety of ways in which PHP performance can be improved, both in how the operating system executes it, and in the language itself.

This chapter starts with a look at PHP modules and extensions — how too many extensions can adversely affect performance, as well as situations in which it can be worth writing your own. After that, you learn about opcode caching, a powerful technique that can overcome many of the limitations of an interpreted ...

Get Professional Website Performance: Optimizing the Front-End and Back-End 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.