Rasmus Lerdorf on scaling web apps with PHP

Rasmus Lerdorf

Rasmus Lerdorf led OSCON attendees through a series of optimizations for modern web applications using PHP at O’Reilly’s Open Source conference today. Most programmers use default installations and configurations for their web applications and never really dig deep within their stack or their own code to optimize page load and latency. The full slides from Rasmus’s talk are available online and I recorded audio of the entire session from the front row.

Rich web applications make better use of browser user interfaces through the use of less visible round-trips to the server (through AJAX or other methods). These new interaction models place increased importance on your server’s ability to respond quickly and frequently to requests, allowing your web app to feel like a desktop app. Rasmus walked through each of the essential components of a rich web app, optimizing each step along the way with the goal of supporting 500,000 users and their 1700 requests/second as seamlessly as possible with less hardware.

Once your web application in complete Rasmus recommends using http_load to evaluate your application performance. How many requests per second can you handle? What is the latency of these requests? Your choices will reflect your app‘s ability to scale.

Once you’ve grabbed some statistics it’s time to dig a bit deeper and understand which processes are responsible for the slowdown. Valgrind is an emulation tool allowing you to step through your Apache server, Zend components, and PHP wrappers to determine the pain-points in your application. You may notice unexpected processes firing off such as SSL for local database connections that are unnecessarily weighing down your app. KCachegrind is useful for visualizing these processes.

Prepared statements can be a bit slow in PHP and skip the query cache. Rasmus recommends using PDO::ATTR_EMULATE_PREPARES in PHP 5 for more optimal data access.

APC is an alternative cache allowing for better query execution. Note: include_once and require_once don’t play nice with opcode caches right now and changing to require. This behavior should be fixed in future versions of APC. APC has a no-stat mode and if you give it absolute paths you can skip the stat() call.You can also store PHP variables in shared memory such as your config.ini file.

PHP 5 adds better XML based on libxml2. SimpleXML is a good tool to load a full XML file and map elements. PHP 5 contains a new SOAP extension written in C and will have an Axis-based version available in a few months.

I may up a full transcript of the talk, but until then you can walk through the slides from Rasmus’s talk.

5 replies on “Rasmus Lerdorf on scaling web apps with PHP”

  1. If it helps someone within Microsoft take PHP more seriously then I’d recommend that you write it up.

    Thanks for this Niall — I had to miss OSCON this year (alas; again) and I would likely have missed this one. Appreciated.

  2. I can’t wait for the Axis-based version of PHP 5. Thanks for providing audio from the Open Source Conference as well as the link to KCachegrind. Very insightful!

Comments are closed.