Mod_php, FastCGI, PHP-FPM and other PHP running mode comparison _ PHP Tutorial

Source: Internet
Author: User
Tags microsoft iis
Mod_php, FastCGI, PHP-FPM and other PHP running mode comparison. Mod_php, FastCGI, PHP-FPM and other PHP running mode comparison this article mainly introduces mod_php, FastCGI, PHP-FPM and other PHP running mode comparison, this article explains what is PHP processor (PHPhandlers mod_php, FastCGI, PHP-FPM and other PHP running mode comparison

This article mainly introduces mod_php, FastCGI, PHP-FPM and other PHP running mode comparison, this article explains what is PHP processor (PHP handlers) mod_php advantages and disadvantages, FastCGI advantages and disadvantages, PHP-FPM (FastCGI Process Manager) advantages and disadvantages of other content, need friends can refer to the next

Overview

I wrote this article because I want to build the LNMP environment under Ubuntu today, Nginx uses a PHP-FPM, so the interaction between the Web server and the PHP interpreter is organized.

As we all know, PHP is a cross-platform and cross-server language, which is also one of the reasons for its popularity. However, few people know that the PHP interpreter can run on the Web server in different ways. The most common method of PHP is to run the module (mod_php) in Apache, which is also the default method for Apache to run PHP. However, in Nginx, Nginx uses PHP-FPM again.

This article will introduce these concepts. if there are any mistakes, please criticize and advise them a lot.

What is PHP handlers )?

Remember that any Web server (such as Apache and Nginx) is designed to send html, images, and other static resources to users, the Web server itself cannot interpret any dynamic scripts (such as PHP and Python ). The PHP processor is used to explain the PHP code in a Web application, interpret it as HTML or other static resources, then pass the parsing result to the Web server, and finally send it to the user by the Web server. Most Web servers cannot parse PHP code, so they need a program that can parse PHP code. this is the PHP processor.

Mod_php

First, let's take a look at running PHP using the Apache module. Mod_php is now available in various Linux software repositories, so it is easy to install.

When PHP runs in Apache as a module, the PHP interpreter is "embedded" in the Apache process. Apache does not call any external PHP process, so this method enables better communication between Apache and PHP. However, when running PHP in this way, even if Apache only provides static resources (such as HTML), every sub-process of Apache will load mod_php, this causes more memory overhead than normal.

Another disadvantage of running in this way is that it can only work with Apache. In addition, this method is not suitable for small VPS and large websites, because large websites may have a lot of static resources which do not need to be explained by PHP programs.

Advantages:

1. easy to install and update

2. capacity configuration

Disadvantages:

1. work with Apache only

2. added memory overhead for Apache sub-processes

3. after changing the php. ini file, restart Apache.

FastCGI

FastCGI is a Common protocol Interface between interactive programs and Web servers. it is a variant of early CGI (Common Gateway Interface. Compared with CGI, FastCGI reduces the overhead of interaction with the Web server and can process more requests at the same time.

Apache can use FastCGI in the form of mod_fcgid. FastCGI can be used on other Web servers, such as lighttpd, nginx, Cherokee, and Microsoft IIS. With FastCGI, you can set multiple PHP versions at the same time, which is useful in some cases.

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

Advantages:

1. compatible with most Web servers

2. smaller memory than mod_php

3. more configuration items, including PHP and suexec

Disadvantages

1. complicated configuration

2. not well known

PHP-FPM (FastCGI Process Manager)

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

The PHP-FPM enables administrators to gracefully stop and start PHP workflows without losing any queries. This allows us to gradually update the configuration and binary without losing any query. It also allows us to restart the process in case of any unexpected damages.

Advantages:

1. compatible with most Web servers

2. smaller memory than mod_php

3. more configuration items, including PHP and suexec

Disadvantages

1. complicated configuration

2. not well known

Supplement: four ways for Apache to run PHP

Mod_php (DSO, Dynamic Shared Object)

CGI

SuPHP

FastCGI

Summary

The content is relatively abstract and not deeply understood. record it for future reference ~ :)

This article mainly introduces mod_php, FastCGI, PHP-FPM and other PHP running mode comparison, this article explains what is PHP processor (PHP handlers...

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.