`
harry
  • 浏览: 179486 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

什么是scgi

阅读更多

SCGI与FastCGI相似,也是CGI的一个替代协议,但是与FastCGI相比,SCGI更容易实现。

Specification

The client connects to a SCGI server over a reliable stream protocol allowing transmission of 8-bit bytes. The client begins by sending a request. See below for the format of the request. When the SCGI server sees the end of the request it sends back a response and closes the connection. The format of the response is not specified by this protocol.

Request Format

A request consists of a number of headers and a body. The format of the headers is:

        headers ::= header*
        header ::= name NUL value NUL
        name ::= notnull+                
        value ::= notnull+
        notnull ::= <01> | <02> | <03> | ... | 
        NUL = <00>

Duplicate names are not allowed in the headers. The first header must have the name "CONTENT_LENGTH" and a value that is a nonempty sequence of ASCII digits giving the length of the body in decimal. The "CONTENT_LENGTH" header must always be present, even if its value is "0". There must also always be a header with the name "SCGI" and a value of "1". In order to facilitate the transition from CGI, standard CGI environment variables should be provided as SCGI headers.

The headers are sent encoded as a netstring. The body is sent following the headers and its length is specified by the "CONTENT_LENGTH" header.

Example

The web server (a SCGI client) opens a connection and sends the concatenation of the following strings:

        "70:"
            "CONTENT_LENGTH" <00> "27" <00>
            "SCGI" <00> "1" <00>
            "REQUEST_METHOD" <00> "POST" <00>
            "REQUEST_URI" <00> "/deepthought" <00>
        ","
        "What is the answer to life?"

The SCGI server sends the following response:

        "Status: 200 OK" <0d 0a>
        "Content-Type: text/plain" <0d 0a>
        "" <0d 0a>
        "42"

The SCGI server closes the connection.


相关:什么是FastCGI
1. FastCGI 像是一个常驻 (long-live) 型的 CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去 fork 一次 (这是 CGI 最为人诟病的 fork-and-execute 模式)。
2. FastCGI 可在任何平台上使用,Netscape Enterprise 及 IIS 都有 FastCGI 的模块可供使用,阿帕契 (Apache,以及利用 Apache 衍生出做的服务器) 上也有 mod_fastcgi 可用。
3. FastCGI 支持 C/C++,Ruby, Perl,Tcl,Java,Python 等程序语言。
4. FastCGI 的应用程序亦兼容于 CGI。即 FastCGI 的应用程序也可以当成 CGI 来执行。
5. 现有的 CGI 程序要改写成 FastCGI 非常简单,最少可能只需要多加入三行程序代码。
6. FastCGI 的侦错方式与 CGI 大同小异,只要带入程序所需的环境变量及参数,即可在命令列模式执行或侦错。
7. FastCGI 应用程序的写作方式与 CGI 类似,除了几项原则要特别注意外,FastCGI 的写作方式跟 CGI 几乎一样,与学习 Web Server API 比较起来, FastCGI 简单多了。
8. FastCGI 支授分布式运算 (distributed computing),即 FastCGI 程序可以在网站服务器以外的主机上执行并且接受来自其它网站服务器来的请求。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics