Pro PHP Application Performance

Armando Padilla, Tim Hawkins

Mentioned 1

Pro PHP Application Performance will help you understand all the technologies and components which play a role in how well your applications run. When seconds can mean the difference between retaining a user and losing a user, it's important for all of us to have optimization as part of our project roadmap. But what components within your application should you analyze? How should you optimize? And how can you measure how well your application is performing? These are some of the questions that are answered in this book. Along the way you will also learn the "why" of optimizing. You’ll discover why you should optimize a specific component, why selecting one function over another is beneficial, and how to find and use the optimization tools available to the open source community. You’ll also learn how to deploy caching software as well as web server software. Pro PHP Application Performance will also teach you more advanced techniques, such as: Using Xdebug to profile functions that are not running as efficiently as possible. Comparing opcode executed by different PHP functions to narrow the search for functions that run efficiently. Using strace to analyze Apache while your application is served to the user. Once you complete this book you will have a complete sense of where to start optimizing and, most importantly, have the tools which allow you to continue optimizing in other PHP applications going forward. What you’ll learn How to improve the performance of existing PHP applications How to maximize the performance of existing operating systems and databases How to refactor existing PHP code for better performance How to identify and rectify bottlenecks in PHP code How to take advantage of variable caching to increase performance Strategies for selecting server hardware for best performance Who this book is for This book will appeal to established PHP developers who wish to write new, complex applications or want to rearchitect existing ones. Developers of other languages such as Ruby, Python, and VB.NET will also have an interest in the techniques for tuning the performance of web servers, databases, and operating systems. Table of Contents Benchmarking Techniques Improving Client Download and Rendering Performance PHP Code Optimization Opcode Caching Variable Caching Choosing the Right Web Server Web Server and Delivery Optimization Database Optimization Installing Apache, MySQL, PHP, and PECL on Windows Installing Apache, MySQL, PHP, and PECL on Linux

More on

Mentioned in questions and answers.

I am currently a placement student (web developer) working for a university, and I have been assigned a few big web projects. The projects include a total revamp of the university i.t. help site which draws around 14k hits a month from on the uni campus and around 4k externally. I also have a second project which is a mobile version of the first project. The projects will be sharing some resources.

To generalise this question so the answers could be useful to more people:

  • I have two websites that will share some resources, lets say, index.php, functions.js and style.css, and these scripts will be used on almost all pages on the websites.
  • I have two audiences to cater for (in terms of download speed), the users within the same network that the sites hosted on (100mb/s aprx) and external users.

I would like to know what would be the best way to cache each kind of script (.js, .css, .php) and examples of how this would be done with their pros and cons over other methods if possible. By caching I mean locally, network and server caching.

Note: index.php is a dynamic page which should be refreshed from cache every 2 hours. It would be cool if you start your answer with .js, .css, .php or a combination so I can easily see what type of script you are talking about caching.

Thanks All!

Performance tuning through cachine could be categorized into multi-layers:

Good introduction and practical code examples can be found in Chapter 9 (Performance) - Developing Large Web Applications. It will talk about Caching CSS, Javascript, Modules, Pages, Ajax and Expire headers.

If we need to keep things simple on server-side do the following:

  1. Install APC extension which will make PHP faster for you through the so called opcode caching. No special configuration, it will work silently for you.
  2. Cache the full page for two-hours using this simple Pear library PEAR::Cache_Lite.
  3. For each database SELECT query cache the result in APC with a TTL of 5 Min, md5 hash the SELECT statement and use it as key for APC cache. Docs

In future if you have multiple servers and the performance becomes to be crucial before then you will need to look at:

  1. Shared memory caching between servers. Check Memecache or even Membase
  2. You need a reverse proxy solution: this basically layer between your user and server server so that it will serve the HTTP requests instead of your server. You can use for that Varnish, Squid or Apache Traffic Server.
  3. Mysql innoDB engine is slow, you may need to go for faster engine such as XtraDB
  4. Then maybe you will find that rational databases are stil slow for you. Then you will go for the key-value solution such as MongoDB.

Finally as references in web application performance check:

  1. Front-end Performance: High Performance Web Sites, Even Faster Web Sites and High Performance JavaScript.
  2. Back-end Performance: Pro PHP Application Performance and High Performance MySQL