什么是通用网关接口(CGI)? [英] What is Common Gateway Interface (CGI)?

查看:83
本文介绍了什么是通用网关接口(CGI)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CGI是通用网关接口。顾名思义,它是所有内容的通用网关接口。从名称来看,它是如此琐碎而幼稚。我感到自己理解了,每次遇到这个词时都会感到。但坦率地说,我没有。我还是很困惑。

CGI is a Common Gateway Interface. As the name says, it is a "common" gateway interface for everything. It is so trivial and naive from the name. I feel that I understood this and I felt this every time I encountered this word. But frankly, I didn't. I'm still confused.

我是一位具有Web开发经验的PHP程序员。

I am a PHP programmer with web development experience.


用户(客户端)请求页面---> webserver(->嵌入式PHP
解释器)---->服务器端(PHP)脚本---> MySQL服务器。

user (client) request for page ---> webserver(->embedded PHP interpreter) ----> Server side(PHP) Script ---> MySQL Server.

现在说我的PHP脚本可以从MySQL服务器中获取结果,并且MATLAB服务器和其他服务器。

Now say my PHP Script can fetch results from MySQL server & MATLAB server & some other server.

那么,现在PHP脚本是CGI吗?因为它的接口为Web服务器和所有其他服务器?我不知道。有时他们称CGI为技术与有时他们将CGI称为程序或其他服务器。

So, now PHP Script is the CGI? Because its interface for the between webserver & All other servers? I don't know. Sometimes they call CGI, a technology & other times they call CGI a program or some other server.


  • 什么是CGI?

  • What exactly is CGI?

什么是CGI? / cgi-bin / *。cgi 有什么大不了?这是怎么回事?我不知道服务器上的 cgi-bin 目录是什么。我不知道为什么会有* .cgi扩展名。

Whats the big deal with /cgi-bin/*.cgi? What's up with this? I don't know what is this cgi-bin directory on the server for. I don't know why they have *.cgi extensions.

为什么Perl总是会出现这种情况。 CGI& Perl(语言)。我也不知道这两个怎么了。几乎我一直都在不断地听到 CGI& Perl的组合。本书是使用Perl进行CGI编程的另一个很好的例子。为什么不使用PHP / JSP / ASP进行CGI编程?我从未见过这样的事情。

Why does Perl always comes in the way. CGI & Perl (language). I also don't know what's up with these two. Almost all the time I keep hearing these two in combination "CGI & Perl". This book is another great example CGI Programming with Perl. Why not "CGI Programming with PHP/JSP/ASP"? I never saw such things.

C语言中的CGI编程,让我非常困惑。 用C ?认真吗?我不知道该说些什么。我很困惑。 用C ?这改变了一切。程序需要编译和执行。这完全改变了我对Web编程的看法。我什么时候编译?程序如何执行(因为它将是机器代码,因此必须作为独立的进程执行)。它如何与Web服务器通信? IPC?并使用套接字编程与所有服务器(在我的示例MATLAB& MySQL中)接口?我迷路了!

CGI Programming in C, confuses me a lot. "in C"?? Seriously?? I don't know what to say. I'm just confused. "in C"?? This changes everything. Program needs to be compiled and executed. This entirely changes my view of web programming. When do I compile? How does the program gets executed (because it will be a machine code, so it must execute as a independent process). How does it communicate with the web server? IPC? and interfacing with all the servers (in my example MATLAB & MySQL) using socket programming? I'm lost!!

人们说CGI已过时,不再使用了。是这样吗?最新更新是什么?

People say that CGI is deprecated and isn't in use anymore. Is that so? What is the latest update?


一次,我遇到了这样的情况: b $ b必须授予HTTP PUT请求访问
Web服务器(Apache HTTPD)的权限。早就回来了。因此,据我所知,这是我所做的

Once, I ran into a situation where I had to give HTTP PUT request access to web server (Apache HTTPD). Its a long back. So, as far as I remember this is what I did:


  1. 将Apache HTTPD的配置文件编辑为告诉网络服务器将
    的所有HTTP PUT请求传递给
    put.php (我必须编写此PHP
    脚本)

  1. Edited the configuration file of Apache HTTPD to tell webserver to pass all HTTP PUT requests to some put.php ( I had to write this PHP script)

执行put.php处理请求(将文件保存到提到的
位置)

Implement put.php to handle the request (save the file to the location mentioned)

人们说我写了一个CGI脚本。
严重的是,我不知道他们在说什么

People said that I wrote a CGI Script. Seriously, I didn't have a clue what they were talking about.




  • 我真的写过CGI脚本吗?

  • 希望您能理解我的困惑。 (因为我自己不知道我在哪里困惑)。我要求你们保持答案尽可能简单。我真的不明白任何花哨的技术术语。至少在这种情况下不是。

    I hope you understood what my confusion is. (Because I myself don't know where I'm confused). I request you guys to keep your answer as simple as possible. I really can't understand any fancy technical terminology. At least not in this case.

    编辑:

    我发现了这个很棒的教程 CGI编程很简单! -CGI教程,以最简单的可能方式解释了这些概念。阅读本文后,您可能需要阅读 C语言中的CGI编程入门用实际的代码示例补充您的理解。我还将这些链接添加到本教程的Wikipedia文章中: http://en.wikipedia.org/wiki / Common_Gateway_Interface

    I found this amazing tutorial "CGI Programming Is Simple!" - CGI Tutorial, which explains the concepts in simplest possible way. After reading this article you may want to read Getting Started with CGI Programming in C to supplement your understanding with actual code samples. I've also added these links to this tutorial to Wikipedia's article: http://en.wikipedia.org/wiki/Common_Gateway_Interface

    推荐答案

    CGI是一个接口,它告诉Web服务器如何在应用程序之间传递数据。更具体地说,它描述了如何在环境变量(例如请求类型,远程IP地址)中传递请求信息,如何通过标准输入传递请求主体以及如何通过标准输出传递响应。您可以参考 CGI规范

    CGI is an interface which tells the webserver how to pass data to and from an application. More specifically, it describes how request information is passed in environment variables (such as request type, remote IP address), how the request body is passed in via standard input, and how the response is passed out via standard output. You can refer to the CGI specification for details.

    要使用您的图片,请执行以下操作:

    To use your image:

    用户(客户端)请求页面--->网络服务器--- [CGI] ---->服务器端程序---> MySQL Server。

    大多数(如果不是全部的话),可以将网络服务器配置为以 CGI的身份执行程序。这意味着网络服务器在收到请求后,会将数据转发到特定程序,设置一些环境变量,并通过标准输入和标准输出来编组参数,以便程序可以知道要查找的位置和内容。

    Most if not all, webservers can be configured to execute a program as a 'CGI'. This means that the webserver, upon receiving a request, will forward the data to a specific program, setting some environment variables and marshalling the parameters via standard input and standard output so the program can know where and what to look for.

    主要优点是您可以从Web运行任何可执行代码,因为Web服务器和程序都知道CGI的工作方式。因此,您可以使用支持CGI的常规网络服务器以C或Bash编写网络程序。这样,并且大多数编程环境都可以轻松使用标准输入,标准输出和环境变量。

    The main benefit is that you can run ANY executable code from the web, given that both the webserver and the program know how CGI works. That's why you could write web programs in C or Bash with a regular CGI-enabled webserver. That, and that most programming environments can easily use standard input, standard output and environment variables.

    在您的情况下,您很可能使用了另一种特定于PHP的通信方式在您的脚本和Web服务器之间,正如您在问题中所提到的,它是一个名为mod_php的嵌入式解释器。

    In your case you most likely used another, specific for PHP, means of communication between your scripts and the webserver, this, as you well mention in your question, is an embedded interpreter called mod_php.

    因此,回答您的问题:


    什么是CGI?

    What exactly is CGI?

    请参见上文。


    / cgi-bin / *。cgi有什么大不了的?这是怎么回事?我不知道服务器上的cgi-bin目录是做什么的。我不知道为什么会有* .cgi扩展名。

    Whats the big deal with /cgi-bin/*.cgi? Whats up with this? I don't know what is this cgi-bin directory on the server for. I don't know why they have *.cgi extensions.

    这是cgi程序的传统位置,许多Web服务器都带有此目录预配置为执行所有二进制文件作为CGI程序。 .cgi扩展名表示期望通过CGI运行的可执行文件。

    That's the traditional place for cgi programs, many webservers come with this directory pre configured to execute all binaries there as CGI programs. The .cgi extension denotes an executable that is expected to work through the CGI.


    为什么Perl总是会妨碍您。 CGI& Perl(语言)。我也不知道这两个怎么了。几乎我一直都在不断地听到 CGI& Perl的组合。本书是另一个使用Perl进行CGI编程的绝佳示例,为什么不介绍使用PHP / JSP / ASP进行CGI编程。我从来没有见过这样的东西。

    Why does Perl always comes in the way. CGI & Perl (language). I also don't know whats up with these two. Almost all the time I keep hearing these two in combination "CGI & Perl". This book is another great example CGI Programming with Perl Why not "CGI Programming with PHP/JSP/ASP". I never saw such things.

    因为Perl很古老(比PHP,JSP和ASP都古老,而CGI早就诞生了老,Perl在CGI刚出现时就已经存在),并以其作为一种很好的语言通过CGI服务动态网页而闻名。如今,还有其他替代方法可以在网络服务器上运行Perl,主要是 mod_perl

    Because Perl is ancient (older than PHP, JSP and ASP which all came to being when CGI was already old, Perl existed when CGI was new) and became fairly famous for being a very good language to serve dynamic webpages via the CGI. Nowadays there are other alternatives to run Perl in a webserver, mainly mod_perl.


    CGI的C语言编程使我非常困惑。在C ??认真吗?我不知道该说些什么。我只是感到困惑。在C中 ??这会改变一切。程序需要编译和执行。这完全改变了我对Web编程的看法。我何时编译?程序如何执行(因为它将是一个机器代码,因此它必须作为独立的进程执行)。它如何与Web服务器通信,IPC和如何使用套接字编程与所有服务器(在我的示例中为MATLAB& MySQL)进行接口连接,我迷路了! / p>

    CGI Programming in C this confuses me a lot. in C?? Seriously?? I don't know what to say. I"m just confused. "in C"?? This changes everything. Program needs to be compiled and executed. This entirely changes my view of web programming. When do I compile? How does the program gets executed (because it will be a machine code, so it must execute as a independent process). How does it communicate with the web server? IPC? and interfacing with all the servers (in my example MATLAB & MySQL) using socket programming? I'm lost!!

    您只需编译一次可执行文件,网络服务器就会执行该程序并将请求中的数据传递给程序并输出接收到的响应。

    You compile the executable once, the webserver executes the program and passes the data in the request to the program and outputs the received response. CGI specifies that one program instance will be launched per each request. This is why CGI is inefficient and kind of obsolete nowadays.


    他们指定CGI效率低下,如今已过时。已弃用,不再使用,是吗,它的最新更新是什么?

    They say that CGI is deprecated. Its no more in use. Is it so? What is its latest update?

    在性能不佳的情况下仍使用CGI至高无上的我需要执行代码。由于前面提到的原因,它效率低下,并且在网络环境中有更现代的方法可以执行任何程序。当前最著名的是 FastCGI

    CGI is still used when performance is not paramount and a simple means of executing code is required. It is inefficient for the previously stated reasons and there are more modern means of executing any program in a web enviroment. Currently the most famous is FastCGI.

    这篇关于什么是通用网关接口(CGI)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆