kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

Even though i have used both CGI/Perl and mod_perl, i know only the over all things about the mod_perl. In order to have more idea abt the difference between these two things, i think this is the right place to ask that.

Can anybody give me in depth idea abt these two things, i mean the difference. I would be thankful if someone can explain with few examples.

Thanks in advance
-prasanna.k
  • Comment on Difference between mod_perl and CGI/Perl

Replies are listed 'Best First'.
Re: Difference between mod_perl and CGI/Perl
by ikegami (Patriarch) on Aug 24, 2005 at 15:34 UTC
    Off the top of my head:
    • The Perl interpreter is embedded in the web server, so it doesn't have to spawn off a seperate process to run your Perl script.
    • The Perl interpreter is embedded in the web server, so it only needs to load your modules and scripts once (kinda), instead of once for every request. This speeds things up.
    • You can hook to any phase of the request processing, not just the content phase. That means you could write a custom log generator, or use your own authentication mechanism for images without actually serving up the images in your Perl script.
    • Access to the web server's internal. This speeds things up and reduces the work the Perl script needs to do.
    • You can use Perl in Apache's configuration file
    • It gives you the ability the run modules which require mod_perl, etc.

    There should be something on the subject at the mod_perl website.

Re: Difference between mod_perl and CGI/Perl
by Arunbear (Prior) on Aug 24, 2005 at 16:43 UTC
    There is a free (and very juicy) book on mod_perl, though it was written before the official release of mod_perl 2.
Re: Difference between mod_perl and CGI/Perl
by punkish (Priest) on Aug 24, 2005 at 17:39 UTC
    ikegami pointed out all the positives of mod_perl over plain cgi, and justifiably so. Keep in mind, however, that the very mechanism that makes mod_perl powerful (keep the perl interpreter and your program in memory) makes it also break many plain cgi scripts, especially when the latter depend on getting their detritus cleaned up simply because of die-ing at the end of their run. In other words, the cgi script starts with the user's invocation, and end at the end (!), while mod_perl scripts don't really end. If you have variables that depend on being "fresh" on every invocation, you will be in trouble.

    I haven't done any work with mod_perl thus far (to speak of), and I guess I have missed its power. However, I haven't really needed its power thus far. The book that Arunbear suggests is going to be very helpful in moving from cgi to mod_perl.

    --

    when small people start casting long shadows, it is time to go to bed
Re: Difference between mod_perl and CGI/Perl
by merlyn (Sage) on Aug 24, 2005 at 18:22 UTC
    I predict (and have already seen) many answers in this thread will confuse "mod_perl" with "Apache::Registry". Keep in mind that Apache::Registry is really only the tip of the iceberg of things you can do with mod_perl. There's a lot more to mod_perl than simply running "CGI-like" scripts from a directory.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.