Selection and comparison of php installation modes mod_php and Fastcgi_PHP tutorial

WBOY
Release: 2016-07-13 10:08:01
Original
880 people have browsed it

Selection and comparison of php installation modes mod_php and Fastcgi

Installing php is faced with the choice of mode. In the past, mod_php mode was chosen because it was more convenient to install. Suddenly today I became concerned about the FastCGI mode, and after a while, I found some discussions on the selection and comparison of mod_php and Fastcgi. Now I am posting it and leaving a mark for further research:

Article 1: The difference between PHP installation modes in apache: fastcgi and mod_php

When talking about fastCgi, we have to talk about Cgi.

The full English name of CGI is Common Gateway Interface, which is usually translated as 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 sends the running results to the HTTP server through the CGI interface, and the HTTP server sends the results to the browser.

The emergence of CGI has changed the WEB from static to dynamic. As the Web becomes more and more popular, many websites need dynamic pages to interact with viewers. The shortcomings of CGI methods are also becoming more and more prominent. Because HTTP needs to generate a dynamic page, the system must start a new process to run the CGI program. Continuous forking is a very time-consuming and resource-consuming task. Here comes FastCGI.

Baidu Encyclopedia About FastCGI

 2. FastCGI can be used on any platform. Netscape Enterprise and IIS have FastCGI modules available, and mod_fastcgi is also available on Apache (Apache, and servers derived from Apache).

 3. FastCGI supports C/C++, Ruby, Perl, Tcl, Java, Python and other programming languages.

 4. FastCGI applications are also compatible with CGI. That is, FastCGI applications can also be executed as CGI.

5. It is very simple to rewrite existing CGI programs into FastCGI, and you may only need to add at least three more lines of program code.

 6. The debugging method of FastCGI is similar to that of CGI. As long as the environment variables and parameters required by the program are entered, it can be executed or debugged in the command line mode.

 7. The writing method of FastCGI application is similar to that of CGI. Except for a few principles that need special attention, the writing method of FastCGI is almost the same as that of CGI. Compared with learning Web Server API, FastCGI is much simpler.

8. FastCGI supports distributed computing, that is, FastCGI programs can be executed on hosts other than the website server and accept requests from other website servers.

mod_php uses PHP as a built-in module of APACHE. Let the apache http server itself support the PHP language, without starting the PHP interpreter for every request to interpret PHP.

Part 2: Performance comparison and selection of mod_php or fastcgi

Using php will definitely reduce the choice of solving this problem. Naturally, there is no need to talk about cgi, but there are still many debates between mod_php and fastcgi.

I found some information and posted it here for reference.

First of all, performance should be the issue that everyone is most concerned about. In addition to the benchmarks of mod_php and fastcgi, there are also some tests of server differences, such as apache vs lighthttpd

 1 mod_php, LightTPD, FastCGI - What’s fastest?

The result of this bechmark is that the performance of Apache (prefork)+Fastcgi+php is the best. It exceeds apache+mod_php and even lightty+fastcgi+php. Of course, the difference in the values ​​obtained from this result is very small. In addition, several results mentioned above all use APC acceleration, and the performance is more than doubled after using APC.

 2 php4-mod-vs-cgi

This bechmark is completed in the php4 environment. The content of summary.txt is 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/a*

+turckcache+zend-optimizer n/a*

 +optimizer 21.23

PHP4 CGI, very complex script (insurance application): requests/s

plain 2.00

+turckcache n/a*

+turckcache+zend-optimizer n/a*

+optimizer 1.72

* = turkcache doesn't support caching of the PHP scripts in CGI mode

I think what needs to be paid attention to in the above results is the case of no cache, because using mod_php or fastcgi is mainly used to generate dynamic pages. The previous cache has better tools to implement, such as squid. Therefore, this result is also the winner of fastcgi, and the difference is not big.

 3 http://buytaert.net/drupal-performance?page=1

The results of this article are exactly the opposite of the above two. After using fastcgi instead of mod_php, "When switching from

to

 We observe a 63% slowdown for anonymous visitors, and a 18% slowdown for authenticated visitors.” The following is the chart

In addition, a comparison with lightty was also made in the benchmark, as shown below:

The conclusion of this article is that Apache+mod_php performs better than Apache+fastcgi. In addition, Apache+mod_php is slightly better than lightty+fastcgi.

4 Finally, let’s see what the fastcgi official said

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 that you should test it according to your own application...

Finally, personal opinion

If the performance difference between mod_php and fastcgi is not very big, I would still prefer fastcgi. After all, this method is more flexible, safer and simpler.

 1 Using fastcgi, your web server can be easily switched, and you can test different servers, such as Apache, lightty, ngix, etc., without any code modification

 2 If you want to change the implementation of the script, such as not using php, but changing it to perl, python or the like, the web server does not need any changes

3 web server and fastcgi can be run with different accounts, which brings a certain degree of security isolation

4 It can be said that it is much simpler to just program mod_fastcgi in Apache. When programming mod_php into apache, it is difficult to determine whether it is a problem with PHP or apache when a problem occurs. I have seen such core and function calls. Dozens of layers and no clue at all.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953966.htmlTechArticleSelection and comparison of php installation modes mod_php and Fastcgi When installing php, we are faced with the choice of mode again. In the past, we always chose mod_php mode, because it is more convenient to install this way, I suddenly became concerned today...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!