in reply to CGI program

1) CGI can mean many things, but first and foremost it's an API. It specifies how a web server can pass data to arbitrary programs. There can be no programs "written in CGI", but programs can use some CGI functionality.

2) not applicable. (and there is no PERL, just Perl (the language) and perl (the compiler)).

3) See answer in 1). Don't you think that other websites (like Wikipedia) have already answered this question?

4) A program can be both a "perl program" (ie written in Perl) and a "CGI program" (a program using the CGI API).

5) I don't understand that question. Are you referring to modules that help you writing CGI programs? If yes, there's CGI.pm, CGI::Minimal and other that can be found on CPAN.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: CGI program
by manishrathi (Beadle) on Sep 23, 2009 at 15:41 UTC
    I did a lot reading before posting questions here and I am still confused.
    In the book "CGI programming with Perl", it was stated that CGI is a protocol. Does it mean that its something like HTTP ? But for using HTTP or LDAP or SQL, we dont use any API. We just open the interface on client machine for LDAP and SQL and comunicate. For HTTP, we dont need to do anything as its default protocol. So my confusion is about CGI being protocol. How can CGI protocol be used ? If we put a perl script in cgi-bin dir, will it automatically use CGI protocol ?
    Is CGI protocol and CGI API, two different things ?
    CGI APIs are created using what language ?
    There are a lot of Perl APIs available, then why CGI APIs are required ? If a program is written in Perl and CGI API is used in it, is that a Perl program or CGI Program ? What does it mean when .cgi extension is used ? When shall we use .cgi extension ?
    Is CGI API in-built in a web server for use ?
    What do you mean by "CGI specifies how a webserver can pass data to arbitrary programs" ? what is meant by "arbitrary programs" ?
    How is CGI API created ? Why do we have to use CGI functionality ? What is it that CGI has which a Perl does not ?
    Is it mandatory to use CGI to pass data to web server ? If we have not used CGI, how will data transfer to "arbitrary programs" ?
    Please excuse me , if some questions are primary. ButI am confused and want to get rid of this confusion.
      It is important to note that the Common Gateway Interface, or CGI, is language independent. Moritz points this out in his point #1. Because it is language independant, you can use Perl or any language that can run under the interface to provide web pages (i.e. bash+CGI, lisp+CGI, python+CGI, etc.).
      CGI states things like:
      • URL parameters are passed as command line parameters to the program
      • Certain environment variables contain other information, like the remote host, the request URL, the user (if authenticated via HTTP basic authentication) etc.
      • HTTP POST data is passed to the standard input of the program

      So you see that CGI is, like HTTP, a specified form to exchange data.

      Unlike HTTP the web server provides all information without asking first. Because CGI is not a networking protocol.

      Perl 6 - links to (nearly) everything that is Perl 6.
      I think most of your confusion is because you don't completely understand the difference between a protocol and a programming language.

      Here on perlmonks you will find many examples of Perl which don't use CGI. If you google 'CGI bash' or 'CGI BAT', you'll also find examples of CGI which don't use Perl.

      Another possible way to get the concepts clear in your head is to try using HTTP without a browser. Run telnet google.com 80 then type GET / and see what happens.

      If all else fails, just start using the language and the protocol, and come back when you have a more specific question.

      In the book "CGI programming with Perl", it was stated that CGI is a protocol. Does it mean that its something like HTTP ?

      Not quite. CGI is a protocol, but it is not a network protocol. It is a protocol defining a method which is used by web server software to interact with other software running on the same host.

      But for using HTTP or LDAP or SQL, we dont use any API. We just open the interface on client machine for LDAP and SQL and comunicate.

      And how do you "open the interface on the client machine"? You run a piece of software which uses the appropriate API to access the underlying protocol to communicate with the HTTP/LDAP/SQL server. Or, if you're writing the client software which does so, you either use an existing API to access the protocol or you implement the protocol yourself.

      If a program is written in Perl and CGI API is used in it, is that a Perl program or CGI Program ?

      Yes. It is both. It is a Perl program which uses CGI. It is also a CGI program written in Perl.

      What does it mean when .cgi extension is used ? When shall we use .cgi extension ?

      The .cgi extension is used to indicate to the web server software (Apache, IIS, etc.) that the file should be executed through the CGI interface instead of sending the file itself to clients requesting that URL. For Apache, this is established by the command "AddHandler cgi-script .cgi" in httpd.conf.

      Is CGI API in-built in a web server for use ?

      It depends on the server you're running. Apache implements CGI as an external module, mod_cgi. Other servers build it into the core feature set.

      What do you mean by "CGI specifies how a webserver can pass data to arbitrary programs" ? what is meant by "arbitrary programs" ?

      "Arbitrary" just means that it can be anything. CGI can be used by a web server to pass data to any program you choose without the server having to know anything special about the program that will be receiving the data.