What is Fastcgi?

Source: Internet
Author: User

 

I. What is FastCGI?
FastCGI is a CGI open extension in a language-independent and scalable architecture. Its main behavior is to maintain the CGI interpreter process in the memory and thus achieve high performance. As we all know, repeated loading of the CGI interpreter is the main cause of low CGI performance. If the CGI interpreter is kept in the memory and is scheduled by the FastCGI Process Manager, it can provide good performance, scalability, fail-over features, and so on.
FastCGI official site in http://www.fastcgi.com
FastCGI works as follows:

1. When the Web server is started, load the FastCGI Process Manager (iis isapi or Apache module );
2. FastCGI Process Manager initializes itself, starts Multiple CGI interpreter processes (multiple php-cgi.exe in the Task Manager), and waits for a connection from the web server.
3. When a client request arrives at the web server, the FastCGI process manager selects and connects to a CGI interpreter. Web server sends the cgienvironment variable and standard input to php-cgi.exe.
4. After the FastCGI sub-process completes processing, the standard output and error messages are returned from the same connection to the web server. When the FastCGI sub-process closes the connection, the request processing is complete. The FastCGI sub-process then waits for and processes the next connection from the FastCGI Process Manager (running in webserver. In the normal cgimode, php-cgi.exe exits.

In the above cases, you can imagine how slow CGI is. Every Web Request PHP must re-Parse PHP. ini, re-load all DLL extensions, and initialize all data structures. With FastCGI, all of these occur only once when the process starts. An additional benefit is that persistent database connection can work.

2. Why use FastCGI instead of multi-thread CGI interpreter?
This may be due to multiple considerations, such:
1. You cannot use the multi-threaded CGI interpreter on windows platform in any way. Whether it is iis isapi or APACHE Module, they will always crash after a period of running. Strange? But this is indeed the case!
Of course, you may also be able to use the multi-thread CGI interpreter in a stable manner. However, you may find that web pages sometimes encounter errors and you cannot find the cause in any case, the probability of such errors is greatly reduced when FastCGI is used. I don't know why. I think the CGI interpreter of an independent address space may be a little more stable than the shared address space.
2. Performance! Performance? Is it possible that FastCGI is faster than the multi-thread CGI interpreter? However, sometimes this is the case. Only by testing your website can you draw a conclusion. I think it is difficult to explain the reason, but I have some information that Zend, In the Zend WinEnabler era, also suggested using FastCGI on Windows platforms rather than IIS ISAPI or Apache Module, however, Zend is no longer using this product.

Iii. Reasons for not using FastCGI
1 Gbit/s multi-path consumes more memory than multi-thread. The php-cgi.exe interpreter consumes 7 to 25 Mbit/s of memory per process. Multiply this number by 50 or 100.
2. Performance. Sometimes the multi-thread CGI interpreter is faster, and sometimes it is stable.

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.