Friday, December 17, 2004

Perl and CGI....

Yesterday was spent in learning the ropes of perl cgi. Once you start learning something and then look back at the times you were wondering what all this greek and gibberish were, u suddenly feel foolish :) !! But dont get me wrong its a great feeling.

CGI standards is actually one of the outdated standards that is present. There are others like JSP's, .NET e.t.c which are more faster and powerful.
The whole setup on CGI can be envisaged as a controller which allows users to communicate with the server. What users see is an html page. This is the interface for them to talk to the server. The users will input some data through the form (html page). This data is then grouped as key-value pairs and sent to the server. The CGI standard has got certain environment values through which these key and values can read and processed. The back end processing is done by Perl. (And Iam assuming that this is possible with other languages also. Which languages ? I do not know now, but maybe I will have something to update with tomorrow !)
Supposes there are 100 users accessing that form, then for CGI, there will be that many instances !! (Yes !!) Consider the same scenario in case of JSP. In this case, there will still be only one instance, which timeshares the info provided by the user with the server !!

In spite of this why do peopel still use CGI ? Iam not sure. Maybe its the compatibility with languages like Perl. Or maybe It was because of legacy considerations !! Maybe I should look into that and see if anything interesting comes up or not .

2 comments:

Randal L. Schwartz said...

CGI means forking, yes. No, CGI doesn't demand Perl, but Perl is most frequently used for CGI. And Perl doesn't demand CGI... the most popular heavy-lifting open-source web server these days is mod_perl - Perl embedded in Apache that doesn't fork (it's not CGI).

If you're not responding to one-hit-per-second or better, CGI is perfectly fine, and Perl is a perfectly fine CGI language. And if you need to scale up to one hit per millisecond, mod_perl is a nice transition.

Raj said...

CGI does work fine when you have a very small load on the server, I mean hits on your website. In short it can handle single threaded operations very well. But the story turns very sour when you are going to need multi threaded environment. You don't want to be pulling down the operating system's capabilities with a single threaded application. That's when multi threaded server environment like .NET, J2EE servers come to the rescue. They not only handle multi threaded applications, but also come with off the shelf packages for transactional capabilities and loads of other functionalities which you couldn't even dream of having with CGI.
If companies don't shift to J2EE or .NET, then it's mostly the cost involved in migrating them. Even though most things in J2EE are open source, supported applications still have a price tag attached to it.