The design of high concurrent server: the design of fastcgi

Source: Internet
Author: User
Tags http request printf

To use FASTCGI in server development, the following methods are used:

while (fcgi_accept () >= 0) {  
                printf ("Content-type:text/plain \ r \ n"
                "Content-length:%d\r\n" "
                Connection:close\r\n\r\n%s\r\n ", strlen (buffer), buffer);  
        

The facgcgi header file has the following macros:

#undef  fprintf  
#define fprintf  fcgi_fprintf  
#undef  printf  
#define printf   fcgi_ Printf

As you can see, the printf function has been macro-turned, and printf in the program is no longer standard output. So there is a problem, if you want to debug print information to stdout, it is not.

Real-world development, there may be a variety of problems, and sometimes do need to print some information, this time you can modify the Fcgi_stdio.h header file, changed to the following:

#undef  _fprintf  
#define _FPRINTF  fcgi_fprintf  
#undef  _printf  
#define _PRINTF   fcgi_printf

Also change the corresponding macros in the appropriate place in the program.

FastCGI parsing can be done through this function:

Char *getenv (const char *name)

There are several types of parameters:

Content_Type

Content_Type GET request Type
Content_length Length of body section
Query_string Request string


Take the following HTTP request message as an example:

Get/s?

ie=utf-8&bs=%e8%bf%99%e6%98%af&f=8&rsv_bp=1&rsv_spt=3&wd=%e6%9c%8d%

E5%8A%A1%E5%99%A8% e5%bc%80%e5%8f%

91&rsv_sug3=11&rsv_sug=0&rsv_sug4=609&rsv_sug1=2&inputt=32681 HTTP/1.1 

 
Host:www.baidu.com  
Connection:keep-alive  
content-type:text/html;charset=utf-8  
accept:text/html,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8  
user-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.31 (khtml, like Gecko) 

chrome/26.0.1410.64 safari/537.31  
www.baidu.com/s?wd=%E8%BF%99%E6%98%

af&rsv_bp=0&ch=&tn=baidu&bar=&rsv_spt=3&ie= utf-

8&rsv_sug3=4&rsv_sug=0&rsv_sug4=240&rsv_sug1=3&inputt=2835  
Accept-Encoding: GZIP,DEFLATE,SDCH  
accept-language:zh-cn,zh;q=0.8  
accept-charset:gbk,utf-8;q=0.7,*;q=0.3  
Cookies: baiduid=a83324e58ae26486e46fc49ed127891b:fg=1; bdsvrtm=163; 

h_ps_pssid=1439_2448_2454_2256_1788_2249; www_st=1369271667063

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.