What are CGI scripts used for these days?

[亡魂溺海] 提交于 2020-07-16 20:23:24

问题


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?


回答1:


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.




回答2:


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?




回答3:


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.




回答4:


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.




回答5:


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




回答6:


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




回答7:


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




回答8:


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




回答9:


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.




回答10:


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.



来源:https://stackoverflow.com/questions/1162029/what-are-cgi-scripts-used-for-these-days

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!