现在 CGI 脚本有哪些用途?

发布于 2024-07-28 22:58:00 字数 135 浏览 5 评论 0原文

我对一般的 Web 编程语言非常熟悉,但我现在使用的工具之一是 CGI。 我只能说 CGI 脚本相当慢。

CGI 如今仍然普遍使用吗? 如果不是,它被什么取代了?
是否存在 CGI 仍然存在并被积极使用的利基功能?

I'm pretty well up to speed on general web programming languages, but one of the tools I'm working with right now is in CGI. All I can tell is that CGI scripts are quite slow.

Is CGI still commonly used today? If not, what has it been replaced by?
Are there any niche functions in which CGI is still alive and actively used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

八巷 2024-08-04 22:58:00

CGI是协议,它是创建动态页面最基本、最标准的方式。

在很多情况下它都是有用的:

  1. 当您想要使用没有 mod_XYZ 的语言(例如 C 或 Haskell)创建一个基本应用程序时,这可能是计算密集型的。
  2. 在嵌入式系统中,内存很昂贵,您更喜欢生成 CGI 脚本
    而不是一直将其保留在记忆中。
  3. 在某些托管服务上,您希望能够灵活地以任何您想要的技术编写服务器端软件,但另一方面,不要使用 FastCGI 将总统应用程序保存在内存中(例如 Sourceforge 托管)。
  4. CGI 上的负载很低,因此您不必关心每个请求生成的应用程序。 例如,在像 MoveableType 这样的博客中,只有更新是通过 CGI 完成的,其余的都由服务提供
    通过静态页面,CGI 脚本会在需要时更改。 所以生成 CGI 脚本的成本
    非常低。
  5. 当您的大部分内容是静态页面并且您希望使用 thttpd 这样的服务器来提供服务时,因此很少有操作可以通过它支持的 CGI 来完成。

所以... CGI 很简单,但仍然非常有用API,允许简单地做事情。

例如,显示服务器正常运行时间的脚本

#!/bin/bash
echo Content-Type: text/plain
echo
uptime

还有什么比这更简单、更容易且更少依赖 Web 服务器的呢?

CGI is protocol, it is most basic and most standard way to create dynamic pages.

There are many cases where it is useful:

  1. When you want to create, a basic application in a language without mod_XYZ, let's say C or Haskell, that may be computation intensive.
  2. In embedded systems, where memory is expensive and you prefer to spawn a CGI script
    rather then holding it in memory all the time.
  3. On some hosting services where you want to give flexibility to write server side software in any technology you want, but on the other hand do not hold president applications in memory using FastCGI (for example Sourceforge hosting).
  4. The loads on CGIs are low so you don't care about spawning applications per request. For example, in blogs like MoveableType, only updates are done via CGI, all the rest is served
    via static pages, which CGI script changes when needed. So the cost of spawning CGI script
    is very low.
  5. When most of your content is static pages and you want to serve it with server like thttpd, so very few operations that are done can be done via CGI that it supports.

So... CGI is simple but still very useful API, allowing to do stuff simply.

For example, the script that shows uptime of your server

#!/bin/bash
echo Content-Type: text/plain
echo
uptime

What can be simpler, easier and less web-server dependent?

稀香 2024-08-04 22:58:00

CGI 已被各种各样的 Web 编程技术所取代,包括 PHP、各种 Apache 扩展(如 mod_perl)、各种风格的 Java 和框架(包括 Java EE、Struts、Spring 等)、基于 Python 的框架(如 Django、Ruby on Rails 等)其他 Ruby 框架以及各种 Microsoft 技术。

我确信 CGI 仍然用于某些事情,但我猜它主要只是一些已经存在多年的代码。 维基百科确实提到 FastCGI 与 CGI 类似,但没有巨大的性能缺陷。

CGI has been replaced by a vast variety of web programming technologies, including PHP, various Apache extensions like mod_perl, Java of various flavors and frameworks including Java EE, Struts, Spring, etc, Python-based frameworks like Django, Ruby on Rails and many other Ruby frameworks, and various Microsoft technologies.

I'm sure CGI is still used for something, but I'd guess it's mostly just little bits of code that have been sitting around for years. Wikipedia does helpfully mention that FastCGI is similar to CGI but without the massive performance drawbacks.

她比我温柔 2024-08-04 22:58:00

如今,许多遗留网站仍然使用 CGI 构建,尽管现在人们正在逐渐放弃它。 据我所知,仍然使用 CGI 的著名应用程序之一是 MovableType 博客

Many legacy websites are still built with cgi today, although people these days are moving away from it. One of the well renown application that is still using CGI that I know is MovableType blog.

别挽留 2024-08-04 22:58:00

无法选择移植的实时操作系统(例如 PHP)。

Real time operating systems where porting (for example, PHP) is not an option.

岁月静好 2024-08-04 22:58:00

我知道有 2 个正在积极开发的项目仍然使用 CGI 脚本,效果良好。

第一个是 Webmin ,一个我已经使用多年的基于 Web 的系统管理工具。

第二个是 GitWeb,它允许您为 Git 存储库设置 Web 界面。

至于 CGI 的速度(或缺乏速度),我无法对此发表评论。 根据我使用 Webmin 的经验,我不能说我在这方面遇到过任何问题。

I know of 2 projects that are being actively being developed that still use CGI scripts to good effect.

The first is Webmin a web-based system administration tool that I've been using for years.

The second is GitWeb which allows you to setup a web interface to your Git repositories.

As to the speed of CGI (or lack thereof) I can't really comment on that. From my experience with Webmin I can't say I've had any issues on that front.

冷情 2024-08-04 22:58:00

我仍然在没有 php 语言支持的嵌入式计算机上使用它。

I still use it on embedded computers which do not have php Language support.

夏有森光若流苏 2024-08-04 22:58:00

许多共享主机通过 CGI 提供服务器端语言,如 PHP、Python 和 Perl

Many shared hosts serve server side languages like PHP, python and perl through CGI

夜空下最亮的亮点 2024-08-04 22:58:00

ASP、PHP、ASP.Net、Ruby on Rails 是当今的大热门。

ASP, PHP, ASP.Net, Ruby on Rails are the big hitters these days.

随遇而安 2024-08-04 22:58:00

就像 Cobol 和 Fortran 一样,有一些基于 CGI 构建的大额货币系统当然会在未来得到维护。

并不是说更新的软件不是时常使用所有这些技术构建的。

Much like Cobol and Fortran there are some big money systems built on CGI that will of course be maintained well into the future.

Not that newer software isn't built with all those technologies from time to time.

蒗幽 2024-08-04 22:58:00

我几个月前离开的一个项目仍然使用 CGI。 然而,该网站适用于非常小的用户群(它只有大约 40 个用户,并且经常使用它的用户可能不到 5 个)。 虽然硬件已经更换了 3 到 4 次,但其中一些代码已经运行了近 10 年,几乎没有修改过。 我确信其他技术会提供性能改进,但目前的性能是可以接受的,并且进行更改的人力短缺,分布在太多领域,并且不熟悉网络技术(尤其是在我离开之后)。 这导致了一种“如果它没有坏,就不要修理它!”的态度。

至于我已经使用/计划调查的替代品:在我的新职位上,我使用 PHP 开发了一个 Web 应用程序。 然而,我更喜欢 Python,并计划很快研究 WSGI。 我还计划使用 AJAX 来替换我自愿维护的非营利性网站上的 CGI 程序。

A project I left a few months ago still uses CGI. However, the site is for a very small user set (it only has about 40 users, and probably less than 5 use it frequently). While the hardware has been replaced 3 or 4 times, some of that code has been running for almost 10 years, with little or no modification. I'm sure other technologies would provide a performance improvement, but current performance is acceptable, and manpower to make a change is short, spread over too many areas, and not well versed in web technologies (especially since I left). This leads to an attitude of "If it ain't broke, don't fix it!"

As for replacements I've used/plan to investigate: In my new position, I've developed a web app with PHP. However, I'm more of a Python fan and plan to look into WSGI soon. I also plan to use AJAX to replace a CGI program on a site I voluntarily maintain for a non-profit.

倾城泪 2024-08-04 22:58:00

CGI 和更新的技术并不相互排斥。 它们可以是互补的。

我的极精度二项式概率计算器(编写于 2020 - 2021 年)是使用 实现的 PHP 和 CGI​​ Perl 与 GMP 一起工作,还有一点点 JavaScript。

Perl 对任意精度算术的支持及其与 GNU 多精度算术库 (GMP) 的接口,使其成为实现此类工具的良好语言。 相同的代码既可以作为 Perl 命令行工具又可以作为 CGI 模块运行。 (事实上​​,在我的服务器上,binomcalc.pl 命令行工具的下载链接实际上只是 binomcalc.cgi 模块的 Linux 符号链接。)

PHP(以及 HTML、CSS 和 JavaScript)更适合创建 Web 界面。

PHP 代码生成一个 CGI include 指令,将参数传递给 Perl 代码。 Perl 和 然后 GMP 代码进行计算并生成结果,该结果显示在网页上。

CGI and newer technologies are not mutually exclusive. They can be complementary.

My Extreme Precision Binomial Probability Calculator (written in 2020 - 2021) is implemented using both PHP and CGI Perl, working together along with GMP, and a tiny bit of JavaScript.

Perl's support for arbitrary precision arithmetic, and its interface to the GNU Multiple Precision Arithmetic Library (GMP), make it a good language for implementing a tool like this. The same code runs both as a Perl command-line tool and as a CGI module. (In fact, on my server the download link for the binomcalc.pl command-line tool is actually just a Linux symlink to the binomcalc.cgi module.)

PHP (and HTML, CSS & JavaScript) are better for creating the Web interface.

The PHP code generates a CGI include directive, passing parameters to the Perl code. The Perl & GMP code then do the calculations, and generate the results, which appear on the web page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文