'What are CGI scripts used for these days?
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?
Solution 1:[1]
CGI is protocol, it is most basic and most standard way to create dynamic pages.
There are many cases where it is useful:
- 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.
- In embedded systems, where memory is expensive and you prefer to spawn a CGI script rather then holding it in memory all the time.
- 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).
- 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.
- 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?
Solution 2:[2]
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.
Solution 3:[3]
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.
Solution 4:[4]
Real time operating systems where porting (for example, PHP) is not an option.
Solution 5:[5]
Many shared hosts serve server side languages like PHP, python and perl through CGI
Solution 6:[6]
I still use it on embedded computers which do not have php Language support.
Solution 7:[7]
ASP, PHP, ASP.Net, Ruby on Rails are the big hitters these days.
Solution 8:[8]
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.
Solution 9:[9]
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.
Solution 10:[10]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Joshua Partogi |
| Solution 3 | |
| Solution 4 | |
| Solution 5 | |
| Solution 6 | |
| Solution 7 | Spencer Ruport |
| Solution 8 | Matthew Vines |
| Solution 9 | PTBNL |
| Solution 10 |
