CGI in a glance

http://www.jdon.com/idea/cgi.htm

 

The Common Gateway Interface (CGI) is a standard protocol that defines how webserver software can delegate the generation of webpages to a console application. Such applications are known as CGI scripts; they can be written in any programming language, although scripting languages are often used.

 

 

Drawbacks

Calling a command generally means the invocation of a newly created process. Starting up the process can take up much more time and memory than the actual work of generating the output, especially when the program still needs to be interpreted or compiled. If the command is called often, the resulting workload can quickly overwhelm the web server.

The overhead involved in interpretation may be reduced by using compiled CGI programs, such as those in C/C++, rather than using Perl or other scripting languages. The overhead involved in process creation can be reduced by solutions such as FastCGI, or by running the application code entirely within the webserver using special extension modules.

 

Alternatives

Several approaches can be adopted for remedying this:

  • The popular Web servers developed their own extension mechanisms that allows third-party software to run inside the web server itself, e.g. Apache modules, Netscape NSAPI plug-ins,IIS ISAPI plug-ins.
  • FastCGI allows a single, long-running process to handle more than one user request while keeping close to the CGI programming model, retaining the simplicity while eliminating much of the overhead CGI incurs by creating a new process for each request. Unlike converting an application to a web server plug-in, FastCGI applications remain independent of the web server.

Alternatives

PHP

JSP

ASP

Python: The Web Server Gateway Interface defines a simple and universal interface between web servers and web applications or frameworks for the Python programming language.

 

Hello, CGI

 

apache in redhat

http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/index.html

http://httpd.apache.org/docs/2.2/howto/cgi.html

 

 

1. start up apache

/etc/rc.d/init.d/httpd start

 

2. write cgi script, under ScriptAlias dir

 

Default cgi script is put under /var/www/cgi-bin

 

/etc/httpd/conf/httpd.conf 

ScriptAlias /cgi-bin/ /var/www/cgi-bin

 

Perl script: hello.cgi

 

 

Shell script: getdate.cgi

 

 

File permissions

Remember that the server does not run as you. That is, when the server starts up, it is running with the permissions of an unprivileged user - usually nobody, or www - and so it will need extra permissions to execute files that are owned by you. Usually, the way to give a file sufficient permissions to be executed by nobody is to give everyone execute permission on the file:

 

chmod a+x first.pl

Also, if your program reads from, or writes to, any other files, those files will need to have the correct permissions to permit this.

 

3. request through browser

 

http://host/cgi-bin/hello.cgi

http://host/cgi-bin/getdate.cgi

 

 


 

 

Directory

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FireCoder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值