Fastest option for a PHP webserver

8,275

Solution 1

Apache is a good base with mod-php - and adding APC for byte-code caching, and some variable caching will help immensely, in fact, it's the most obvious thing you can do to speed up PHP scripts run-times (also, use Yslow to speed the HTML front-end and make sure that the database is optimised).

There are a few suggestions I'd add though, such as avoiding serving the images and other static content from Apache. I've got a separate (sub-)domain with a dedicated image server (I use thttpd, but nginx is also entirely suitable). Serving the images from an entirely separate domain name (or a CDN) would be ever better though.

NginX also has the advantage of being able to act as a proxy, which has it dealing with inbound connections, and then spoon-feeding the results back out - which means that the back-end producer processes of Apache2/Mod_php can work at full local-network speeds, rather than having to wait for the web-browser clients to catch up.

Varnish can perform additional work beyond what Nginx can do, but I don't know it so well - it might be you could just one one, or the other, but it's unlikely to have to use both.

Solution 2

nginx combined with php-fpm and xcache will provide massive speed improvements over any Apache solution.

Depending on your application incorporating something such as memcache may also provide massive caching advantages.

Share:
8,275

Related videos on Youtube

Smashery
Author by

Smashery

Updated on September 17, 2022

Comments

  • Smashery
    Smashery almost 2 years

    I need to serve a PHP app that handles lots of requests. I want to know if there's any real benefit in going with anything other than Apache, and what are the pros and cons of the alternatives.

    I have some experience using lighttpd and nginx for Rails applications. Are they good contenders for PHP too? Any important setup tricks?

    How about PHP accelerators, can they be used with these alternative servers, is it a good idea?

    I'm on an OpenSolaris box.

    Not sure if relevant, but, later on, I'm planning to put a Varnish proxy/cache in front of this server.

    Edit:

    I'd like to add that I have absolutely no intention of touching the app. It's the quintessential mess that PHP is famous for, and there's basically no time.

    • Admin
      Admin about 15 years
      Once you've got the low-hanging fruit of speed improvements with APC, profile the site - first with Yslow, and then the PHP. It might be a mess, but a good developer could still find places where it could be enormously improved for just a little bit of work.
    • Admin
      Admin almost 11 years
  • Smashery
    Smashery about 15 years
    memcache would be great, the queries are awful. maybe I'll try to get a php guy on it.
  • Adam Gibbins
    Adam Gibbins about 15 years
    Agreed, the queries aren't great but its certainly worth while putting up with them as it provides a great performance improvement over standard disk caching.
  • cletus
    cletus about 15 years
    Why server images from another server/domain?
  • Joseph Anderson
    Joseph Anderson about 15 years
    To avoid cookies being sent with the request. If you're only interested in static content, why send any more that just the required headers in the HTTP handshake? There's enough overhead there without adding maybe a few hundred more bytes (heck, even the extra bytes for a minimal 'Cookie: PHPSESS=[MD5]\n' can add up if you're doing that for every request)
  • Eduard Luca
    Eduard Luca about 11 years
    Well let's be honest. Wordpress is a crappy (to say the least) blog system. It's actually one of the worst I've ever seen, down there with Drupal and a few others. Benchmarking a "hello world" script in PHP says that Apache does about the same as nginx (in fact a bit better), if your AllowOverride is set to None.