cgi_and_fastcgi
CGI
来自维基百科
In computing, Common Gateway Interface (CGI) offers a standard protocol for web servers to execute programs that execute like Console applications (also called Command-line interface programs) running on a server that generates web pages dynamically. Such programs are known as CGI scripts or simply as CGIs. The specifics of how the script is executed by the server are determined by the server.[1] A CGI script essentially reads a query string and produces a HTML page.[2]
CGI接口定义了server如何执行脚本并返回一个HTML页面.
实际上, 在网络发展早期, 浏览器向服务器发送HTTP请求, 首先会到达Http Web Software, 如IIS, Apache, Nginx, Node-js服务器等. 然后这些服务器捕获了这些HTTP请求, 会解析出请求的内容, 并将具体的请求内容调用一些脚本或者程序, 执行完之后会组成html的输出, 返回给client端. CGI就是HTTP请求通过服务器软件传给脚本的接口定义.
This is usually done by marking a directory within the document collection as containing CGI scripts - its name is often cgi-bin. For example, /usr/local/apache/htdocs/cgi-bin could be designated as a CGI directory on the web server. When a Web browser requests a URL that points to a file within the CGI directory (e.g., http://example.com/cgi-bin/printenv.pl/with/additional/path?and=a&query=string), then, instead of simply sending that file (/usr/local/apache/htdocs/cgi-bin/printenv.pl) to the Web browser, the HTTP server runs the specified script and passes the output of the script to the Web browser. That is, anything that the script sends to standard output is passed to the Web client instead of being shown on-screen in a terminal window.
由web server执行脚本, 但这里的脚本或者软件, 都应该是命令行的, 在web server中会有一个目录(虚拟, 总之是一个Dict结构, 映射了url和script的对应关系), 如果收到client的对文件的请求, web server就会把本来返回脚本文件的行为变为执行脚本, 然后返回脚本输出到标准输出的内容, 并返回给client.
As remarked above, the CGI standard defines how additional information passed with the request is passed to the script. For instance, if a slash and additional directory name(s) are appended to the URL immediately after the name of the script (in this example, /with/additional/path), then that path is stored in the PATH_INFO environment variable before the script is called. If parameters are sent to the script via an HTTP GET request (a question mark appended to the URL, followed by param=value pairs; in the example, ?and=a&query=string), then those parameters are stored in the QUERY_STRING environment variable before the script is called. If parameters are sent to the script via an HTTP POST request, they are passed to the script's standard input. The script can then read these environment variables or data from standard input and adapt to the Web browser's request.[10]
这里还涉及到对于HTTP请求方式的不同, 上面的例子上是当请求server software的脚本文件时,
请求是
http://example.com/cgi-bin/printenv.pl/with/additional/path?and=a&query=string
如果是HTTP GET请求, 在请求脚本文件后还加了/with/additional/path
, 这个会被保存在一个环境变量中PATH_INFO
中, 而后面的请求参数也会被保存在一个环境变量QUERY_STRING
中.
如果是HTTP POST请求, 在HTTP请求体里面的参数会被重定向到脚本的标准输入, 然后执行脚本.
FastCGI
FastCGI是CGI的一个变种, 是一个二进制协议, 目的在于减少server software和CGI pragrams的过度交互, 并使server可以一次处理多个请求. CGI Application是one request, one process, 效率比较低.
FastCGI可以认为是web server和application的中间层, FastCGI有一个一直存在的service process, 通过socket, pipe或者是TCP和web server的进程通信, 会不断把请求参数传递给application.
Python WSGI
WSGI(Web Server GateWay Interface)
在CGI和FastCGI之上, Python实现了WSGI, 作为对于使用Python开发web application时同web server的接口. WSGI中有middleware的概念, 类似于FastCGI, 也是中间层.
cgi_and_fastcgi的更多相关文章
随机推荐
- Flask_restful 插件实战笔记——基本概念与使用
最近在Resetful接口设计上想法还是挺多的,也实现了一些需求!想着整理下Flask_restful插件的基本知识,方便日后的复习! 官方地址:https://flask-restful. ...
- 《剑指offer》面试题16—反转链表
Node* p1 p2 p3 思路:开始时,p1为NULL,p2=phead,p3=p2—>next.使p2—>next = p1,然后使p1=p2,p2=p3.如果只有1个结点则此时 ...
- win10+PHP 安装memcache
1.给php环境安装memcache扩展 2.给电脑安装memcache环境 一.为win10安装memcache服务 下载对应的版本 32位系统 1.4.5版本:http://static.runo ...
- MFC对话框程序 屏蔽ESC和ENTER键关闭对话框的方法
http://blog.csdn.net/xgx198831/article/details/6713651 MFC对话框程序 屏蔽ESC和ENTER键关闭对话框的方法 或许还有其它更好的办法,但下 ...
- HDU5950【矩阵快速幂】
主要还是i^4化成一个(i+1)^4没遇到过,还是很基础的一题矩阵快速幂: #include <bits/stdc++.h> using namespace std; typedef lo ...
- 进击python第三篇:基础
基础拾遗 序列解包 例: >>>x,y,z=1,2,3 >>>print x,y,z 1 2 3 交换变量也是没问题 >>>x,y=y,x > ...
- 15.split分割注意事项
1.v = 'k1,v1- k2,v2- k3,v3-'变成一个字典{'k1':'v1','k2':'v2','k3:'v3'...} 变成一个字典 {'k1':'v1','k2':'v2','k3: ...
- perl 处理特殊字符
如果大家想使用perl 来处理一些特殊字符,例如"del"这种字符,就需要使用到chr() 函数了 例如大家如果向一个文本中写入以下内容 aaaa0x1270x1bccccc 这时 ...
- 页面嵌套时js失效解决方法
事件:iframe或easyui的dialog嵌套页面时,被嵌套的页面可能js因位置失效; 解决: //动态加载js(根据父级html位置计算) jQuery.getScript("scri ...
- Codeforces 997D(STL+排序)
D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...