PHP installation mode mod_php and fastcgi selection and comparison _php tutorial

Source: Internet
Author: User
Tags apc benchmark php language

PHP installation mode mod_php and fastcgi selection and comparison


Install PHP also faced with the choice of mode, before the choice of mod_php mode, because it is easy to install HA, today suddenly concerned about fastcgi this mode, sepsis a handful of mod_php and fastcgi to find some of the choice and comparison of this discussion, Now issued to leave a mark for further study:

First: PHP installation mode differences in Apache: FastCGI and mod_php

Speaking of fastcgi, you have to say CGI.

The English full name of CGI is Common Gateway Interface, usually translated as a common Gateway interface, which is an interface for HTTP servers to communicate with other programs on the machine. This "other program" can be written in any computer language, which obtains input from the HTTP server through the CGI interface, and then passes the result of the operation to the HTTP server via the CGI interface, which the HTTP server sends to the browser.

The advent of CGI makes the web from static to dynamic, as the web becomes more and more popular, many sites need to have dynamic pages, in order to cross with the browser. The shortcomings of the CGI approach are also becoming more prominent. Because HTTP is generating a dynamic page, the system must start a new process to run the CGI program, and the fork is a time-consuming and resource-intensive task. That's where the fastcgi comes in.

Baidu Encyclopedia about FastCGI

2. The FastCGI can be used on any platform, Netscape Enterprise and IIS have FastCGI modules available, and there is also mod_fastcgi available on Apache, as well as servers using Apache-derived server.

3. FastCGI supports C/c++,ruby, Perl,tcl,java,python and other programming languages.

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

5. The existing CGI program to be rewritten into FastCGI is very simple, at least may need to add more than three lines of program code.

6. The debug mode of FastCGI is similar to CGI, and can be executed or debugged in command-line mode as long as the environment variables and parameters required by the program are brought in.

7. The FastCGI application is written in a similar way to CGI, with the exception of several principles, and FastCGI's way of writing is almost the same as CGI, which is much simpler compared to learning the Web Server API FastCGI.

8. FastCGI distributed Operations (distributed computing), that is, the FastCGI program can execute on a host other than the Web server and accept requests from other Web servers.

Mod_php is to make PHP a built-in module for Apache. To enable the Apache HTTP server itself to support the PHP language, do not need every request to start the PHP interpreter to explain PHP.

Article two: mod_php or fastcgi performance comparison and selection

With PHP certainly less than the choice of this problem, CGI naturally do not have to say, but mod_php and fastcgi argument is still more.

Find some information, hanging here, for reference.

First of all, performance should be the most concern for everyone, in addition to the mod_php and fastcgi benchmark, there are some server differential testing, such as Apache vs LIGHTHTTPD

1 mod_php, LightTPD, Fastcgi-what ' s fastest?

The result of this bechmark is that Apache (prefork) +fastcgi+php performance is the best. More than the apache+mod_php, even more than the lightty+fastcgi+php. Of course, the result is a small difference in value. In addition, the above-mentioned results are used by APC acceleration, with APC performance increased by more than 1 time times.

2 php4-mod-vs-cgi

This bechmark is done in a 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/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

The above results I think the need to focus on is a cache-free situation, 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 fastcgi win, the difference is not big.

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

The result of this article is exactly the opposite of the two above. 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. " Here is the chart

In addition, the benchmark also made comparisons with Lightty, such as:

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

4 Finally, let's see what FastCGI officially said.

Of course, the answer is the it depends upon the application. A more complete answer is the FastCGI often wins by a significant margin, and seldom loses by very much.

5 conclusion is, or according to their own application test it ....

Finally, personal opinion

If the performance difference between mod_php and fastcgi is not very large, or is inclined to fastcgi, this way is more flexible, safe and simple.

1 using fastcgi, your Web server can be simpler to switch, can test different servers, Apache,lightty,ngix and so on, do not need to have code modification

2 If you want to change the implementation of the script, such as not PHP, but instead of Perl,python, the Web server does not need any changes

3 Web server and fastcgi can be run with different accounts, resulting in a certain degree of security isolation

4 only in Apache to make a mod_fastcgi can be said to be more simple, put mod_php into Apache, when the problem is difficult to locate is PHP question or Apache problem, I have seen such a core, function call dozens of layer, a little clue is not.

http://www.bkjia.com/PHPjc/953966.html www.bkjia.com true http://www.bkjia.com/PHPjc/953966.html techarticle PHP installation mode mod_php and fastcgi selection and comparison of the installation of PHP is also faced with the choice of the mode, before the choice of mod_php mode, because this installation is more convenient ha, today suddenly concerned about ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.