A ramble on CGI FastCGI WSGI

Source: Internet
Author: User

CGI (Common Gateway Interface)

Initially, CGI was developed in 1993 by the National Supercomputer Application Center (NCSA) for the NCSA HTTPd Web server.

The Web server uses the UNIX shell environment variable to hold parameters passed from the Web server, and then generates a separate process to run the CGI. The first implementation of CGI was written by Perl in 1.

    • Inefficient: Each connected fork is processed by one process.

    • Very limited functionality: CGI receives only one request and outputs a response. It is difficult to control Web requests in the CGI system, for example: User authentication.

Because of these problems, for a long time after the birth of CGI, various Web servers still use the strong binding way of API to support web development, in which Apache's mod_php is this way. So there's a great God behind the fastcgi standard.

FastCGI (Fast Common Gateway Interface)

FASTCGI uses a process/thread pool to process a series of requests. These processes/threads are managed by the FASTCGI server, not the Web server. When a request comes in, the Web server passes the environment variable and the page request through a long socket connection to the fastcgi process. So fastcgi has the following advantages:

    • Performance: Bypass the overhead of CGI opening up new processes through the process/thread pool.

    • Compatible: Very easy to retrofit existing CGI standard programs.

    • Language-Independent: FastCGI is a set of standards, theoretically speaking, as long as the standard output (STDOUT) language can be used as the FASTCGI standard Web backend.
      The following is a pseudo-code for a simple fastcgi backend

void Main (void)
{
int count = 0;
while (fcgi_accept () >= 0) {
printf ("content-type:text/html\r\n");
printf ("\ r \ n");
printf ("Hello world!\r\n");
printf ("Request number%d.", count++);
}
Exit (0);
}
    • Web server isolation: The fastcgi back end and Web server run in different processes, and any failure of the backend does not cause the Web server to hang.

    • Patent: No intellectual property issues for private APIs such as Apache mod_php.

    • Extensions: fastcgi backend and Web server communicate through sockets, both distributed and easily scaled out.

As a result, fastcgi almost all of the mainstream Web server support, Apache, LIGHTTPD, IIS, Cherokee ...

But, there is always room for improvement, fastcgi this set of work mode is actually not much of a flaw, but some restless Python program ape think, fastcgi standard write asynchronous Web service is not very convenient, if you can receive the request after the CGI side to deal with, It is not very coooool?! to return the result by callback callback after processing. So the WSGI was created:

WSGI (Web Server Gateway Interface)

The Web Server Gateway Interface (Interface, abbreviated as WSGI) is a simple and common interface between a Web server and a Web application or framework defined for the Python language.

After the Web server receives a request, the environment variable and a callback callback function can be passed to the backend Web application via the socket, and the Web application returns the content to the Web server via callback after the page is assembled. There are many advantages to doing so:

    • Asynchronously, by callback the work of the Web request, it is convenient to handle multiple Web requests simultaneously in one thread space.

    • It facilitates various load balancing and request forwarding, and does not cause back-end Web applications to block.

    1. Web development is 3p:perl, Python, PHP. Perl was released in 1987, Python is 1989, and PHP is 1995 years old. The CGI standard was presented when Perl was at its zenith, so the CGI proposal was also primarily designed to address the need for Perl as a web programming language. Programmers familiar with regular (regex) may know that the regular fact standard is called PCRE (Perl-compatible regular expressions, Perl Compatible Regular Expressions), This also reflects the impact of Perl as an ancient language on various industry standards at the time.


Welcome to join reboot Operation Development thousand people (365534424) Technical exchange sharing every day has

This article is from the "Reboot DevOps Development" blog, please be sure to keep this source http://opsdev.blog.51cto.com/2180875/1669516

A ramble on CGI FastCGI WSGI

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.