What is the difference between fastcgi and fpm?
Asked Answered
P

3

141

I am trying to install php with fpm on macports. I read somewhere that fpm means FastCGI process manager. Does that mean fastcgi and fpm are same? If they are same, then why do we have two different macports variants for php namely "php5 +fastcgi" and "php5 +fpm"

Pictogram answered 24/12, 2010 at 12:11 Comment(0)
T
98

FPM is a process manager to manage the FastCGI SAPI (Server API) in PHP.

Basically, it replaces the need for something like SpawnFCGI. It spawns the FastCGI children adaptively (meaning launching more if the current load requires it).

Otherwise, there's not much operating difference between it and FastCGI (The request pipeline from start of request to end is the same). It's just there to make implementing it easier.

Teach answered 24/12, 2010 at 12:48 Comment(2)
A key advantage of php-fpm is that one APC cache can be shared across multiple processes. With fcgid, the APC cache is per-process. Using fpm can result in big memory savings, which allow you to use that saved memory to spawn more processes, and serve more traffic.Footer
@cam8001: that's completely not true. You can set in SpawnFCGI how many processes to spawn, and the number of PHP children per process. So spawning 1 PHP process, with 100 children is the same thing as using FPM with 100 children... However, the reverse is true. If FPM gets killed (segfault, whatever), your entire worker dies. In SpawnFCGI, if one of the processes dies, the rest can remain alive... So it's not a clear one-is-better-than-the-other. Different approaches. FPM is recommended not for technical reasons, but because it's maintained along side core (in it actually)...Teach
P
63

What Anthony says is absolutely correct, but I'd like to add that your experience will likely show a lot better performance and efficiency (due not to fpm-vs-fcgi but more to the implementation of your httpd).

For example, I had a quad-core machine running lighttpd + fcgi humming along nicely. I upgraded to a 16-core machine to cope with growth, and two things exploded: RAM usage, and segfaults. I found myself restarting lighttpd every 30 minutes to keep the website up.

I switched to php-fpm and nginx, and RAM usage dropped from >20GB to 2GB. Segfaults disappeared as well. After doing some research, I learned that lighttpd and fcgi don't get along well on multi-core machines under load, and also have memory leak issues in certain instances.

Is this due to php-fpm being better than fcgi? Not entirely, but how you hook into php-fpm seems to be a whole heckuva lot more efficient than how you serve via fcgi.

Picnic answered 16/8, 2011 at 10:29 Comment(2)
Are such issues till around (April 2017)?Antecede
Any updates about the version of lighttpd and fpm you used is recommended, any updates of the mentioned issues still appearing (June 2018) is also helpful to the community.Sternson
G
13

Running PHP as a CGI means that you basically tell your web server the location of the PHP executable file, and the server runs that executable

whereas

PHP FastCGI Process Manager (PHP-FPM) is an alternative FastCGI daemon for PHP that allows a website to handle strenuous loads. PHP-FPM maintains pools (workers that can respond to PHP requests) to accomplish this. PHP-FPM is faster than traditional CGI-based methods, such as SUPHP, for multi-user PHP environments

However, there are pros and cons to both and one should choose as per their specific use case.

I found info on this link for fastcgi vs fpm quite helpful in choosing which handler to use in my scenario.

Ghastly answered 19/5, 2020 at 20:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.