Why is PHP-FPM performing better on Apache for me than it is with Nginx?

I've been doing some benchmarking with latest version of each server. My tests show nginx clearly being faster for static files. Though I've noticed that with default settings for php-fpm Apache with mod_php is actually faster than either server with php-fpm. But after a few minor tweaks to that pool php-fpm is performing same or better at times than mod_php. Nginx and Apache for small concurrencies perform about the same.

The problem I can't figure out though is that once I test higher concurrencies (200+) Nginx starts spitting out a lot of 500 errors. Whereas on my same machine Apache using php-fpm has 100% availability (despite Nginx being below 20% availability). It's continues like that with much higher concurrencies too. Apache performs just fine without issue or much performance hit at concurrencies of 700 or so connections. Whereas Nginx can't handle more than 150 without massive failures.

Am I missing something here? A setting that results in failures to proxy requests to php-fpm less efficiency in Nginx than in Apache?

4 thoughts on “Why is PHP-FPM performing better on Apache for me than it is with Nginx?”

  1. I’m curious as well to know if anyone’s got advice.

    One thing I would recommend though is offering up some more concrete examples of what’s happening and how it’s setup. What does the FPM config look like? The pool config? What about the nginx config? And finally, whats showing in the logs when you start getting 500s? Are fpm processes terminating or is the script generating errors?

  2. How many worker processes are you using for each?

    What are you using to benchmark?

    If you had that high of concurrency you would definitely be using a reverse proxy cache like nginx or Varnish as well.

  3. Sounds like you’re hitting fastcgi timeouts in nginx (you’re using nginx fastcgi -> php-fpm, right?), check error log.
    What response times are we talking here? Anything over 60s should be considered failure anyway.

    If it is indeed related to nginx cutting slow requests, you can try increasing these settings:


    Might have to increase fastcgi buffer sizes/count aswell and don’t forget to increase worker_connections in events block, since you’re gonna have a lot of slow connections.

    If you have FPM on same server as nginx, be sure to use sockets instead of TCP (more efficient).


Leave a Comment