Php installation mode mod_php and Fastcgi selection and comparison. Php installation mode mod_php and Fastcgi selection and comparison and installation of php are also faced with the choice of mode, the previous use of mod_php mode, because this installation is more convenient, today, I was suddenly concerned with the selection and comparison of the php installation modes mod_php and Fastcgi.
The installation of php is also faced with the mode selection. Previously, the mod_php mode was used, because it is more convenient to install it. today, I suddenly started to care about the FastCGI mode, which has been compromised, I have found some discussions on the selection and comparison of mod_php and Fastcgi, and now I have issued a mark for further research:
Article 1: differences between the installation mode of php in apache: fastcgi and mod_php
Speaking of fastCgi, you have to say Cgi.
CGI is the Common Gateway Interface, which is usually translated as a Common Gateway Interface. it is an Interface for the HTTP server to communicate with other programs on the machine. This "other program" can be written in any computer language. it obtains input from the HTTP server through the CGI interface, and then delivers the running result to the HTTP server through the CGI interface, the HTTP server sends the result to the browser.
The emergence of CGI changes the WEB from static to dynamic. as the Web becomes increasingly popular, many websites need dynamic pages to interact with viewers. The disadvantage of CGI is becoming more and more prominent. To generate a dynamic page for HTTP, the system must start a new process to run the CGI program. continuously fork is a task that consumes a lot of time and resources. FastCGI appears.
Baidu Encyclopedia about FastCGI
2. FastCGI can be used on any platform. Netscape Enterprise and IIS both have FastCGI modules for use. Apache (and servers derived from Apache) also have mod_fastcgi available.
3. FastCGI supports C/C ++, Ruby, Perl, Tcl, Java, Python, and other programming languages.
4. FastCGI applications are also compatible with CGI. That is, the FastCGI application can also be executed as CGI.
5. it is very easy to rewrite the existing CGI program to FastCGI. at least three lines of program code must be added.
6. The FastCGI debugging method is similar to CGI. you only need to bring the environment variables and parameters required by the program into the command column mode to execute or detect errors.
7. the writing method of FastCGI applications is similar to that of CGI. in addition to the several principles, FastCGI writes almost the same way as CGI, which is compared with learning Web Server APIs, fastCGI is much simpler.
8. FastCGI supports distributed computing, that is, the FastCGI program can run on a host other than the website server and accept requests from other website servers.
Mod_php uses PHP as a built-in module of APACHE. The apache http Server supports the PHP language and starts the PHP interpreter to explain PHP without every request.
Article 2: Performance Comparison and selection of mod_php or fastcgi
With php, there must be fewer choices. cgi naturally doesn't have to be said, but there are still a lot of arguments between mod_php and fastcgi.
I found some information for your reference.
First of all, the performance should be the most concerned. in addition to the benchmark of mod_php and fastcgi, there are also some tests on server differences, such as apache vs lighthttpd.
1 mod_php, LightTPD, FastCGI-What's fastest?
The result of this bechmark is that Apache (prefork) + Fastcgi + php has the best performance. Exceeds apache + mod_php, or even lightty + fastcgi + php. Of course, the difference in the result is very small. In addition, the above results all use APC acceleration, and the performance is improved by more than doubled after APC is used.
2 php4-mod-vs-cgi
This bechmark is completed in the php4 environment. The contents of its summary.txt are as follows.
------------------------
PHP4 module, very simple script (phpinfo. php): requests/s
Plain 130.04
+ Turckcache 129.42
+ Turckcache + zend-optimizer 125.50
PHP4 module, very complex script (insurance application): requests/s
Plain 1.84
+ Turckcache 6.23
+ Turckcache + zend-optimizer 5.58
+ Optimizer 1.58
PHP4 CGI, very simple script (phpinfo. php): requests/s
Plain 22.69
+ Turckcache n/*
+ Turckcache + zend-optimizer n/*
+ Optimizer 21.23
PHP4 CGI, very complex script (insurance application): requests/s
Plain 2.00
+ Turckcache n/*
+ Turckcache + zend-optimizer n/*
+ Optimizer 1.72
* = Turkcache doesn' t support caching of the PHP scripts in CGI mode
I think the above results need to be concerned about the absence of cache, because mod_php or fastcgi is mainly used to generate dynamic pages. The previous cache has better tools to implement it, such as squid. Therefore, this result is also fastcgi's victory, and the difference is not big.
3 http://buytaert.net/drupal-performance? Page = 1
The result of this article is the opposite of the two above. After fastcgi is used to replace mod_php, "When switching from
To
We observe a 63% slowdown for anonymous visitors, and a 18% slowdown for authenticated visitors. "The following is a chart
In addition, benchmark is compared with lightty, for example:
The conclusion in this article is that Apache + mod_php has better performance than Apache + fastcgi. In addition, Apache + mod_php is slightly better than lightty + fastcgi.
4. Finally, let's take a look at what fastcgi officially says.
Of course, the answer is that it depends upon the application. A more complete answer is that FastCGI often wins by a significant margin, and seldom loses by very much.
5. The conclusion is, test it based on your own application ....
My opinion
If the performance difference between mod_php and fastcgi is not great, fastcgi is preferred. after all, this method is more flexible, secure, and simple.
1. with fastcgi, your web server can be easily switched to test different servers, such as Apache, lightty, and ngix without any code modifications.
2. if you want to change the implementation of scripts, such as using php instead of perl or python, the web server does not need any changes.
3. web server and fastcgi can run with different accounts, resulting in certain security isolation.
4 compiling mod_fastcgi in Apache is much simpler. when mod_php is compiled into apache, it is difficult to locate whether it is a php issue or an apache issue. I have seen such a core, there is no clue at all when there are dozens of layers of function calls.
In the past, I chose the mod_php mode to install php in composer, which is easy to install. today I suddenly started to care about it...