PHP and Squid

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

This is interesting:

Perhaps the most significant change to PHP performance I have experienced since I first wrote this article is my use of Squid, a web accelerator that is able to take over the management of all static http files from Apache. You may be surprised to find that the overhead of using Apache to serve both dynamic PHP and static images, javascript, css, html is extremely high. From my experience, 40-50% of our Apache CPU utilisation is in handling these static files (the remaining CPU usage is taken up by PHP running in Apache).

It is better to offload downloading of these static files by using Squid in httpd-accelerator mode. In this scenario, you use Squid as the front web server on port 80, and set all .php requests to be dispatched to Apache on port 81 which i have running on the same server. The static files are served by Squid.

This is also part of the reason that Nginx became popular: it is highly optimized for serving static content.

Nowadays I’m all about handling as much as possible from my Clojure code, but I put my static files on a dedicated server where Nginx has not other responsibility other than serving those static resources. I usually point some sub-domain at that server, so that something like images.tma.com points to a server whose only job is serving images.

Post external references

  1. 1
    http://phplens.com/lens/php-book/optimizing-debugging-php.php
Source