mod_php vs cgi vs fast-cgi

PhpInterpreterFastcgiMod Php

Php Problem Overview


I have been trying to understand the exact meaning/purpose of loading php as an apache module vs the rest.

When php is installed as an apache module, what exactly happens? For example, does reading the php-ini file happen every time the php request comes or when the php module is loaded alone?

Php Solutions


Solution 1 - Php

php.ini is read when the PHP module is loaded in both mod_php, FastCGI and FPM. In regular CGI mode, the config file have to be read at runtime because there's no preforked processes of any kind.

I think the only real advantage of running PHP as a module inside the web server is that the configuration might be easier. You get a lot better performance when you run it in FastCGI or FPM mode and can use a threaded or evented (instead of forked) Apache, or when you can throw out Apache altogether.

Solution 2 - Php

This link may help: http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html

> Conclusion > > If pure speed is what you are after, then stay with mod_php. > > However, for better resource usage and efficiency, consider moving to > fcgid.

Solution 3 - Php

php.ini is read when the module is loaded in the case of an Apache module. PHP CGI uses a php interpreter executable like any other shell script would do. Since there is no state involved at each invocation, the config file would have to be read every single time in case of CGI.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKarthickView Question on Stackoverflow
Solution 1 - PhpEmil VikströmView Answer on Stackoverflow
Solution 2 - PhpstormwildView Answer on Stackoverflow
Solution 3 - PhpAnandView Answer on Stackoverflow