davej Posted July 27, 2012 Share Posted July 27, 2012 Are CGI scripts obsolete or do they fill some particular niche? 1 Link to comment Share on other sites More sharing options...
boen_robot Posted July 28, 2012 Share Posted July 28, 2012 CGI isn't really a language, but a protocol for applications. PHP is a CGI application. Or to be more precise, it can be used as a CGI application.Most other languages that have a CGI reputation (Ruby, Perl) aren't exactly CGI applications themselves... but they do allow you to output CGI compatible output.In fact, if you run a PHP from "php.exe", and output HTTP headers using "echo", you are in essence creating a CGI application. Link to comment Share on other sites More sharing options...
davej Posted July 28, 2012 Author Share Posted July 28, 2012 (edited) Ok, I had scanned the Wikipedia entry before posting my question and my understanding was that CGI implies that the webserver is set up to launch some executable program in response to particular page accesses -- but why do this? Why not just use ordinary server-side code? Are there some things that the CGI approach is better at? Or is CGI an older, semi-obsolete approach? Thanks Edited July 28, 2012 by davej Link to comment Share on other sites More sharing options...
boen_robot Posted July 28, 2012 Share Posted July 28, 2012 Yes. That's what CGI is - a protocol that defines what an executable program should expect as input (in STDIN, environment variables, etc.), and what it is expected to write in STDOUT for the web server to handle it properly.Server side code boils down to one of 3 approaches:1. A self-contained web server. No Apache or something like it needed - you just create a program using a certain language/framework, compile it (no way around that...), and start the generated executable.2. A web server module. This is one of the ways in which PHP could run as, and one way in which you could write your own modules. The server may provide a way for you to write interpreted rather than compiled code (which is what the PHP Apache module does).3. A CGI/FastCGI executable. This is the other way PHP runs as. FastCGI is basically the same as CGI, except that the executable is expected to remain available after the first request. And PHP just happens to be a (Fast)CGI application that lets you execute interpreted code.I guess what I'm trying to say is that "ordinary server-side code" is a very loosely defined term... basically, there's no such thing.It's like you're asking "Why should I use XML if I can just use XHTML or RSS?". Link to comment Share on other sites More sharing options...
davej Posted July 28, 2012 Author Share Posted July 28, 2012 Ok, I'm under the impression that almost all webservers use Apache or Microsoft IIS server software. The server software then interprets HTML files or somehow launches server-side code which might be Java/JSP, ASP, ASP.NET, PHP, or I don't know what else. Is CGI exactly the same thing or is it something different? Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted July 28, 2012 Share Posted July 28, 2012 or somehow launches server-side code which might be Java/JSP, ASP, ASP.NET, PHP, or I don't know what else.BINGO! That's what CGI is. It's the "somehow" in the sentence above - the most popular way in fact, although from the above list, only PHP uses it. Link to comment Share on other sites More sharing options...
davej Posted July 30, 2012 Author Share Posted July 30, 2012 I guess the intention of my original question was to ask whether something like Perl is still desirable to augment the server-side code of a website? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 30, 2012 Share Posted July 30, 2012 People who use Perl or Python do so because they feel that it is better suited or faster for what they're trying to do. In the absence of benchmarks where you specifically test each language, it pretty much comes down to personal preference. People use Perl because they are Perl programmers. Link to comment Share on other sites More sharing options...
davej Posted July 31, 2012 Author Share Posted July 31, 2012 Ok, I had wondered if there was perhaps some standard reason to mix some of these server-side languages. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now