Faster, PHP! Kill! Kill!

Posted on 21st March 2010 by Nio in 程序人生 - Tags: , ,

Faster, PHP! Kill! Kill!

What most developers don’t realize is that there are three major factors that typically slow down PHP projects based on frameworks (like Symfony or, sigh, Drupal) so much that code profiling and database query redesign don’t even have a chance to become relevant factors. Fix these things first before you worry about other issues:

1. Compiling code over and over and over. Would you wait for your Mac to recompile MacOS X from source code every time you boot it up? Of course not. How about every time you fill out a dialog box? That’s pretty much what you’re doing every time you access a PHP-driven website that doesn’t use a bytecode cache.

2. Waiting and waiting and waiting for web browsers to make another request, pinning down web server processes that your other users need. By default Apache usually lets browsers hold on to a connection for up to 15 seconds just in case they ask for more. This is a good thing in many ways, but 15 seconds is far too long. Which leads us to #3:

3. Tying up a “fat” web server process with PHP on board for every request, even requests for the zillions of little static PNGs that probably make up your page design. (**) A typical Apache web server configuration with mod_php suffers from this flaw, fatally limiting the number of simultaneous users you can handle.

So what can we do about these problems? Quite a bit as it turns out. I’ll start with the low-hanging fruit and move on to the tougher stuff. The fascinating common thread with all of these suggestions: no changes at all to your PHP code.

Optimize Parallel Downloads to Minimize Object Overhead

Posted on 19th July 2009 by Nio in Cache, 程序人生 - Tags: ,

Optimize Parallel Downloads to Minimize Object Overhead

Summary: With the average web page growing past 50 external objects, object overhead now dominates most web page delays. Increasing parallel downloads by using multiple hostnames can realize up to a 40% improvement in web page latency.

浏览器对于同一域名下的文件(图片、JS、CSS)加载是依次进行的,当一个页面中的这些外部对象太多的时候,这种加载延迟会给访问者造成很慢的感觉。通过使用多个域名,解析到同一个服务器,可以“欺骗”浏览器,使其同时对这些外部对象并行加载,从而加快客户端的加载速度。在这基础之上,还可以使用 CDN 进一步优化服务器端,使 B/S 加载速度平衡。