Use EF to develop Web applications (2): Hi, FastCGI (see figure)

Source: Internet
Author: User
ArticleDirectory
    • Web Server Selection

Question:Use "easy language. Flying" (EF) to develop Web ApplicationsProgramThere is no precedent. However, because the EF Local Development Kit (efndk) has been released, it is not difficult to use C/C ++ to develop an EF class library to support EF in developing web applications. Of course, we can imagine that there are many difficulties to solve. This series of articles is a record of my exploration process and may not be of much value to outsiders. If some netizens are optimistic about it, please wait rationally. Author: liigo. For more information, see http://blog.csdn.net/liigo /. Online messages.

Use EF to develop Web applications (2): Hi, FastCGI

In the previous article, we have selected FastCGI as the technical solution for EF to develop Web applications, and mentioned that the FastCGI class library (FastCGI. efn, click to download) of EF has been initially completed ). Next we will try EF to write our first network application.

See the following "easy language. Flying" (EF)Source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Introduce FastCGI;

Public class startup class
{
Public static startup ()
{
Int Count = 1;
Fcgi = New Fcgi ();
While(Fcgi. Accept ()> = 0)
{
Fcgi. Output ("Content-Type: text/plain \ r \ n ");
Fcgi. Output ("Hi, FastCGI.". Duplicate (count ));
Count ++;
}
}
}

See the aboveCode, Especially "while (fcgi. accept ()> = 0) ", I think many friends familiar with FastCGI programming will smile, haha, it's so much like, it's clearly a typical FastCGI programming mode.

Now let's analyze the above Code. Line 3 introduces the FastCGI class library. Lines 3rd to 6 are the syntax elements of the EF language. Row 7th defines an integer variable count, which will be discussed later. Row 3 creates a fcgi variable of the fcgi type (this type comes from the class library FastCGI. efn. Line 3: Call fcgi. Accept () to receive HTTP requests from the client cyclically ). Line 3 calls the fcgi. Output () method to notify the Web server of the content type to be returned. This is required. Line 3 calls the fcgi. Output () method to return the data content to the client. In row 3, the variable count value is added with 1 based on the original value.

According to the FastCGI principle, when multiple client requests arrive, the program flow will always flow in the while loop at line 1. If there is no client request, the program flow will be suspended at fcgi. accept. This is also the main reason why FastCGI is more efficient than CGI (CGI starts CGI every time it receives a request, and then exits after execution ). We can verify this through the Count variable. The initial value of count is 1 in row 7th. After receiving a request, the value of count is added to 1. The output content of row 12th depends on the value of count. Therefore, the result is: output "Hi, FastCGI. ", the second (refresh) Output twice" Hi,
FastCGI. ", the third (refresh) Output three times ....... Online Demo. The following picture confirms our inference:

 

(The suffix of the URL File ". efcgi" depends on the Web server configuration. Here, the suffix "Ef" + "fcgi" is used .)

Web Server Selection

To run the FastCGI program, you must have a web server that supports FastCGI. Currently, mainstream Web servers provide FastCGI support.

Lighttpd
It is a lightweight Web server with good performance, low memory and CPU resource consumption, and has been specially optimized for FastCGI. nginx ("engine X ") it is a high-performance HTTP and reverse proxy server, which is well-known for its fast, low consumption, stability, and high concurrency. Although Apache is famous, it is said that FastCGI support is not very good, is the last selection.

Run FastCGI application development and testing in the Windows operating system. You can select myserver. I am using this Web server for development and testing.

 

Next preview: Use query string.

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.