PHP installation Mode mod

Source: Internet
Author: User
Tags apc benchmark install php php language php and phpinfo zend

Install PHP and face to the choice of mode, before is the choice of mod_php mode, because it is easier to install HA, today suddenly concerned about fastcgi this model, sepsis a handful of mod_php and fastcgi to find some of the choice and comparison of this aspect of the discussion, Now send out to leave a mark for further study:

First: PHP in Apache installation mode difference: fastcgi and mod_php

When it comes to fastcgi, you have to say CGI.

The CGI English full name is Common Gateway Interface, which is usually translated into a common Gateway interface and 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 sends the results of the operation to the HTTP server via the CGI interface, which is sent to the browser by the HTTP server.

CGI makes the web from static to dynamic, as the web becomes more and more popular, many sites need to have dynamic pages, so as to exchange with the visitors. The shortcomings of the CGI approach are becoming more and more prominent. Because HTTP to generate a dynamic page, the system must start a new process to run the CGI program, constantly fork is a time-consuming and resource-intensive work. This shows up the fastcgi.

Baidu Encyclopedia about FastCGI

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

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

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

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

6. FastCGI debugging is similar to CGI, as long as the required environment variables and parameters to the program, you can execute or debug in the command line mode.

7. FastCGI applications are written in a similar way to CGI, with the exception of a few principles to pay special attention to, FastCGI's writing is almost the same as CGI, compared to learning Web Server APIs, FastCGI is much simpler.

8. FastCGI grants distributed operations (distributed computing), that is, FastCGI programs can be executed 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. Let the Apache HTTP server itself be able to support the PHP language, without requiring every request to start the PHP interpreter to explain PHP.

Second: mod_php or fastcgi performance comparison and selection

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

Find some information, hang here, for reference.

First of all, performance should be the most concerned about the problem, in addition to 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 the performance of Apache (Prefork) +fastcgi+php is the best. More than the apache+mod_php, and even more than the lightty+fastcgi+php. Of course, this results in a very small difference in value. In addition, the above several results are used APC acceleration, the use of APC after the performance increased by more than 1 time times.

2 php4-mod-vs-cgi

This bechmark is done 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/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 results above I think need to focus on the situation is no cache, because the use of mod_php or fastcgi is mainly used to generate dynamic pages. The front 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 just 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. Here's the chart.

In addition, benchmark and lightty are also compared, as shown in the following figure:

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 the official FastCGI said.

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

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

Finally, a personal view

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

1 use fastcgi, your Web server can be relatively simple to switch, you can test different servers, Apache,lightty,ngix and so on, do not need to have code changes

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

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

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

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.