mod_php, FastCGI, PHP-FPM and other PHP operating methods to compare _php skills

Source: Internet
Author: User
Tags fpm versions vps

Overview

Writing this article is because today to build the LNMP environment Ubuntu, Nginx use is PHP-FPM, so the Web server and the PHP interpreter interactive way to do a collation.

As we all know, PHP is a cross-platform, Cross-platform language, which is one of the reasons why it is so popular. However, few people know that the PHP interpreter can be run in a Web server in a different way. The most common way of PHP is to run it in the form of a module (mod_php), which is the default way to run PHP in Apache. But in Nginx, Nginx again uses PHP-FPM.

This article on these concepts to make an introduction, if there is a wrong place, please criticize the advice.

What is a PHP processor (PHP handlers)?

The first thing to remember is that any Web server (Apache, nginx, etc.) is designed to send users HTML, pictures, and other static resources, the Web server itself does not explain any dynamic script (PHP, Python, etc.). The PHP processor is used to interpret the PHP code in the Web application and interpret it as HTML or other static resources, and then pass the results of the resolution to the Web server, which is then sent to the user by the Web server. Most Web servers cannot parse PHP code, so it requires a program that parses the PHP code, which is the PHP processor.

mod_php

First, take a look at the Apache module to run PHP. Mod_php is now available in every Linux version of the software repository, so it's easy to install.

When PHP runs in the form of a module in Apache, the PHP interpreter is "embedded" in the Apache process. Apache does not invoke any external PHP processes, so this way the Apache can communicate better with PHP. However, when running PHP this way, even if Apache provides only static resources (such as HTML), every child of Apache will load mod_php, resulting in more memory overhead than normal.

Another disadvantage of running in this way is that it works only with Apache. In addition, in small VPS and large Web sites, this approach is not appropriate, because the large web site may have a lot of static resources, and these static resources do not need to explain the PHP program.

Advantages:
1. Easy to install and update
2. Capacity Configuration
Disadvantages:
1. Can only work with Apache
2. Increased Apache child process memory overhead
3. When you change the php.ini file, you need to restart Apache

FastCGI

FastCGI is a common protocol interface between an interactive program and a Web server, and is a variant of the early CGI (Common Gateway Interface). Compared to CGI, fastcgi reduces the overhead of interacting with Web servers and can handle more requests at once.

Apache can use fastcgi in the form of mod_fcgid. Other Web servers, such as LIGHTTPD, Nginx, Cherokee, and even Microsoft's IIS can also use fastcgi. With fastcgi, you can set up multiple versions of PHP at the same time, which is useful in some cases.

FastCGI also uses suEXEC to support different users using their own instance of PHP. This feature is especially important for improving security in a shared environment. FastCGI also reduces the memory overhead of the Web server while ensuring performance.

Advantages:
1. Compatible with most Web servers
2. Less memory than mod_php
3. More configuration items, including multiple versions of PHP and suEXEC
Disadvantage
1. Complex configuration
2. Not known by everyone

PHP-FPM (FastCGI Process Manager)

PHP-FPM is a new way for Web servers to use PHP and is another implementation of PHP fastcgi. PHP-FPM is very useful for Web applications running on small VPS and multiple servers. It can also be used by any Web server that is compatible with fastcgi.

PHP-FPM enables an administrator to gracefully stop and start a PHP worker process without losing any queries. This allows us to incrementally update the configuration and binaries without losing any queries. It also allows us to restart the process urgently in the event of any accidental disruption.

Advantages:
1. Compatible with most Web servers
2. Less memory than mod_php
3. More configuration items, including multiple versions of PHP and suEXEC
Disadvantage
1. Complex configuration
2. Not known by everyone

Add: Apache runs PHP in four ways

mod_php (dso,dynamic Shared Object)
Cgi
suphp
FastCGI

Summarize

The content is relatively abstract, the understanding is not deep, the record remains for the future reference ~:)

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.