Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_php vs cgi vs fast-cgi

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?

like image 572
Karthick Avatar asked Oct 17 '10 15:10

Karthick


People also ask

What is the difference between mod_php and PHP-FPM?

Unlike PHP-FPM, mod_PHP locks out processes and disrupts the performance of a website. If your primary goal for hosting your web application with an optimized cloud service is to achieve optimal performance and security, then PHP-FPM is the way forward.

What is the difference between CGI and FastCGI?

What makes a difference from CGI is that with FastCGI the running process of the application lasts longer and it is not immediately terminated. After the application finishes processing and returns the output data, the process is not terminated and is being used for processing further requests.

What is CGI and FPM?

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.

What is mod_php?

mod_php means PHP, as an Apache module. Basically, when loading mod_php as an Apache module, it allows Apache to interpret PHP files (those are interpreted by mod_php ).


3 Answers

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.

like image 185
Emil Vikström Avatar answered Oct 14 '22 07:10

Emil Vikström


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.

like image 23
stormwild Avatar answered Oct 14 '22 07:10

stormwild


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.

like image 2
Anand Avatar answered Oct 14 '22 07:10

Anand