r/PHPhelp • • May 26 '20

PHP FPM vs Apache mod_php

Looking to support http2 and have read about switching to fpm to support it. I can handle all that, but I’m curious on a technical level.

Performance wise how does fpm compare to mod_php?

Is FPM the “future?” and is Apache planning on supporting http2 for their php module?

Am I an ancient for still using mod_php

15 Upvotes

6 comments sorted by

4

u/_thegingerninja May 26 '20

mod_php/prefork will never support HTTP/2, in fact, that feature was specifically removed from it as of version 2.4.27+. So in a "modern standards" conversation, yes you'd be considered "old" using mod_php. But still, the world isnt perfect, hundreds of thousands of servers still run it.

FPM is a lot more efficient in terms of resource usage when handling multiple connections, and obviously the MPM's (worker and event) both support HTTP/2.

In short I guess, if you want to, and/or need to, then switching to FPM is the way to adopt HTTP/2

3

u/CyberJack77 May 26 '20

If you look at the Apache wiki pages, you will see they recommend using Apache 2.4 with proxy_fcgi and php-fpm. https://cwiki.apache.org/confluence/display/HTTPD/PHP

mod_php is used to run php as a apache module. Each thread (or request) will start a copy of the php module. Be aware that this module will also be loaded for each css or image request. These requests don't need php, but apache does not know that upfront, so it will load the module. In short, using mod_php is not very memory friendly. Also the php process is run as the apache user, which may cause some permission problems when hosting multiple sites or using cli scripts.

php-fpm is supported by Apache, but also by other web servers like Nginx. php-fpm is a more advanced version of FastCGI and runs as it's own process. Apache will only connect to this process when a php file needs to be processed. Therefor the entire process uses less memory compared to using mod_php. Configuration of php-fpm can be configured much better than the mod_php version, which gives you more control over the process. Also your PHP processes may run using a different user. You can even run multiple php-fpm instances (on different ports) which allow you to run multiple php versions at once. This is something you cannot do with mod_php.

Performance wise there isn't much difference between using mod_php and php-fpm, but modern installations mostly use php-fpm because of the configuration options.

1

u/C0rn3j Nov 04 '24

Note that with mod_php you are forced to use mpm_prefork instead of the modern mpm_event - https://serverfault.com/questions/383526/how-do-i-select-which-apache-mpm-to-use/383634#383634

1

u/raunchieska Jul 12 '23

Is FPM the “future?”

fpm has been around for a long long time. And I wouldn't call it the future - the roadrunner and swoole are what I would use if I start the PHP project today.

1

u/nacholibrev Aug 25 '23

I was wondering the same thing and I couldn't find definitive answer which is better so I've conducted my own tests and performance benchmark.

It turns out Nginx with PHP-FPM is a a little bit faster, but a lot more stable under load.

I've wrote an article about this in my blog, you can check it out, I've added bar charts comparison.

https://yarnaudov.com/mod-php-vs-php-fpm-performance-benchmark.html