What is the cgi,fastcgi,fpm,cli,mod of PHP?

Source: Internet
Author: User
Tags fpm install php

A few questions about PHP

This topic comes from my experience of using PHP for Web crawlers. For a web developer, the PHP interpreter itself is very little known, it is ashamed of it!

First of all, this topic starts with a few questions.

What is PHP?

Foreign name: Php:hypertext Preprocessor, Chinese name: "Hypertext Preprocessor", is a common open source scripting language.

The so-called hypertext preprocessor is intended to be in the HTML and other such text sent to the browser before the server-side processing, so as to dynamically send the original static files. PHP founders intended to provide the convenience of dynamic web development, to provide a preprocessing module for web development, so the early PHP is more like a web development tool set, and then PHP development became huge, independent become an interpreter, and have their own language specifications.

The reason to know the origin is that we need to understand that PHP was born for web development, but later he was too strong to become a new language!

Therefore, the most primitive idea of PHP is to combine with the Web server, so how to combine the language and server software? This raises the following question.

What is a Web server?

such as: Nginx,apache,iis,tomcat, there are some languages such as Nodejs, can provide web-enabled software, the implementation of the HTTP protocol service software is called Web software, the server that installed the software is called a Web server. (The web and HTTP relationship is that the Web is a collection of software built on the HTTP protocol, and web software is an implementation, and HTTP is just a protocol). The most basic feature of web software is Request,response, which is the ability to process users ' requests and respond to them. So Php,python,ruby what the language itself does not have a half-dime relationship with them.

The combination of PHP (language) and Apache (Web software)?

Php_mod

Referring to PHP how to run on the Apache server, you have to mention a module under Apache, Php_mod, is this module let PHP interpreter become a sub-process Apache, sub-module, so that Apache can create a call to PHP process, Thus realizing the so-called Lamp,wamp architecture.

In this case, PHP and Apache is a dependency, Apache boot need to load the PHP module, read the php.ini file, one of the most obvious feature is: in the CGI mode after modifying php.ini do not need to restart the Web server, and Php_ Changing the php.ini in mod mode will require you to restart Apache.

How does PHP combine with Nginx?

fast-cgi

Referring to nginx how to run PHP, you have to mention fast-cgi, to say that fast-cgi will have to say what CGI is a thing.

CGI: protocol, the specification of communication between Web software and scripting language, is intended to enable Web software to standardize the invocation of those scripting languages, such as Php,python,js.

FAST-CGI: Implementation, FAST-CGI is a CGI implementation, NGINX is this implementation, so nginx can and PHP "communication."

Nginx this CGI mode and Apache the biggest difference is that PHP and nginx two software run independently of each other, Nginx needs to execute PHP files to php-fpm to do, processing results in accordance with the CGI specification returned to Nginx,nginx processing finished sent to the user.

In addition, the fast-cgi in the original CGI specification has also been improved, CGI original rule is that each request to create a new process or thread, closed, so the biggest drawback is that the one-off performance is very expensive. So the fast-cgi approach is to start a process in the Web server at the same time, and pre-boot child processes, threads, placed in the process pool waiting for the Web request come over, so nginx once request come, can immediately processing, no longer open a process, so efficiency, performance has been significantly improved.

Because CGI is just a communication protocol, it also supports distributed operations where the FAST-CGI program can execute and accept requests from other Web servers on hosts other than the Web server.

FastCGI the entire process:

    1. Loading the FASTCGI process Manager when Web server starts
    2. FASTCGI itself initialization, starting multiple CGI interpreter processes (visible multiple php-cgi) and waiting for requests from the Web server
    3. When requesting Web server, Web server fastcgi the process manager through the socket request, the FASTCGI process manager selects and connects to a CGI interpreter, the web The server sends CGI environment variables and standard input to the FASTCGI child process php-cgi
    4. After the FASTCGI process requests are completed, the standard output and errors are returned from the same connection to the Web server, and the request ends when the fastcgi child process finishes. The fastcgi child process then waits to process the next connection from the FASTCGI process Manager, and in CGI mode, the php-cgi exits.

php-fpm

PHP-FPM is the FAST-CGI process Manager for PHP.

PHP can be a separate language

Php-cli

Already said, PHP is now a separate scripting language, so PHP provides CLI programming, GUI programming, but also preserves the most important web programming. PHP-CLI is actually a language interpreter, if the use of PHP is only a crawler, algorithm development, only need to install PHP-CLI can, what cgi,fpm do not need, Under Windows is called Php.exe, as long as the CLI, you can directly parse the php file under CMD.

PHP comes with a Web server

Many people use more apache,nginx, do not know PHP and Nodejs, the same, with the Webserver module, you can start directly through PHP 80 port monitoring of the webserver.

As follows:

php -S 127.0.0.1:8080 -t /var/www/html/

What is the cgi,fastcgi,fpm,cli,mod of PHP?

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.