How does FastCGI work on a web server (eg. Apache 2.2+)? How does FastCGI work on a web server (eg. Apache 2.2+)? apache apache

How does FastCGI work on a web server (eg. Apache 2.2+)?


The speed gain from FastCGI over normal CGI is that the processes are persistent. e.g. if you have any database handles to open, you can do them once. Same for any caching.

The main gain comes from not having to create a new php/perl/etc. interpreter each time, which takes a surprising amount of time.

If you wanted to have multiple concurrent connections handled, you do have to have multiple processes FastCGI Processes running. FastCGI is not a way of handling more connections through any kind of special concurrency. It is a way to speed up individual requests, which in turn will allow handling of more requests. But yes you are right, more concurrent requests requires more processes running.


FastCGI spawned processes are persistent, they're not killed once the request is handled, instead they're "pooled".


B, yes IF the cost of spawning is zero then legacy CGI would be pretty good. So if you don't have a lot of hits plain old CGI is fine, run with it. The point of fast cgi is doing things that benefit from a lot of persistent storage, or structures that have to be built BEFORE you can get your work done, like running queries against large databases, where you want to leave the DB libraries in memory instead of having to reload the whole shebang every time you want to run a query.

It matters when you have LOTS OF HITS.