princepawn has asked for the wisdom of the Perl Monks concerning the following question:
I have had numerous reactions to mod_perl over the years from blind support to indifference. My most recent influence vis-a-vis mod_perl was looking through the docs of CGI::Portable. This is a very platform and server-dependent framework, allowing programs to work in CGI, mod_perl, standalone environments regardless of OS or webserver (except that mod_perl only runs on Apache).
So here is my statement about mod_perl as of now:
mod_perl allows for programmatic control of all phases of the request cycle for the popular Apache webserver. As such
mod_perl, like Perl itself has two major uses - administration and applications. In its role for adminstration, the sole purpose of mod_perl is server configuration and control.
Oftentimes, this role slops over into it's other role as a view-technology for web applications following the CGI protocol.
Just as one may write an application acting as if there were only only database, one could do the same for CGI frameworks and only use mod_perl. However, this is unfair to those on other OSes or platforms.
Re: How do you feel about mod_perl?
by count0 (Friar) on Nov 05, 2001 at 20:13 UTC
|
For my uses, mod_perl has always been primarily a source of performance increases in applications. I personally, haven't used some of it's more Apache-related aspects. So with that said, I won't really comment on the administration side of using mod_perl.
What it does for application programmers, which seems to have been largely overlooked in your statement, is greatly increase the efficiency of using Perl for web applications.
Rather than having a perl process started, loaded, etc etc each time a request is made to the webserver, mod_perl allows the perl interpretter to be embedded in Apache. This also provides an effective way to cache scripts and modules, and allows for persistant data.
Just as one may write an application acting as if there were only only database, one could do the same for CGI frameworks and only use mod_perl. However, this is unfair to those on other OSes or platforms.
(Assuming you meant "only one database" ;) ... The only real dependancy mod_perl draws on is Apache. A web application can be easily written to use either CGI or mod_perl (that is, if it doesn't need to directly use Apache's resources with mod_perl.. in which case you don't have many other options anyway ;). In most (of the few) cases, it is simply a matter of something like if ($ENV{MOD_PERL}) {} else {}. A classic example of this was the printing of HTTP headers. When using mod_perl, the programmer would make use of Apache::* methods such as send_http_header(), and header() with CGI. CGI.pm is getting more and more mod_perl friendly though. Using this same example, CGI.pm now checks in certain circumstances whether or not it is in a mod_perl environment... and you can use CGI::header() either way.
Well, i've probably strayed far from what you are asking... and I'm sure it's obvious that I am a mod_perl advocate ;) but I hope this somewhat helps you to decide whether or not mod_perl is suitable for your needs. | [reply] [d/l] |
Re: How do you feel about mod_perl?
by echo (Pilgrim) on Nov 05, 2001 at 20:55 UTC
|
For me, mod_perl has 3 advantages over plain CGI:
- Performance. Everyone knows about this one: the Perl interpreter is embedded in the server process, the scripts are compiled only once. No forking and recompiling at every request.
- Access to all request phases. CGI is limited to the content delivery phase. mod_perl lets you write your own authentication handlers, access handlers, logging, whatnot. One very useful handler is the translation handler, which lets you determine how you will serve the content at runtime, as opposed to a static configuration.
- mod_perl exposes the Apache API, whereas mod_cgi only offers a handful of environmental variables. Escape URIs and encode HTML faster than those pure Perl modules from CPAN. Issue subrequests to do your own SSI-like thing. Many possibilities, the Apache API is very rich.
| [reply] |
Re: How do you feel about mod_perl?
by alfie (Pilgrim) on Nov 05, 2001 at 21:06 UTC
|
There is one major advantage in mod_perl you don't have to forget: speed. CGI itself has to be parsed each time it is called, the interpreter has to be loaded... Yes, I know that there are some fastcgi things that help there, but mod_perl is really fast.
I don't understand why it should be unfair to other OSes or platforms? Apache runs on every OS/platform one wants it to run on - at least on those which can be considered as useful OSes/platforms for running a webserver at all. So I don't get it what's unfair there. That's just a bogus reason for people who really mean IIS and not OS/platform.
Personally I even go further: I use HTML::Mason which is the greatest thing I've ever seen for website programming. I don't really know how argument handling is handled in pure mod_perl, but HTML::Mason makes it really save - one of the things cgi scripts usually are accused for. It also lets you template your site with splitting design completely and cache different components you are using for differnet times. Also session management is quite easy - just give it a try, look at http://www.masonhq.com/. Of course you can use CGI::Portable within HTML::Mason for your things, it's perl, after all.
--
use signature;
signature(" So long\nAlfie"); | [reply] |
Re: How do you feel about mod_perl?
by kwoff (Friar) on Nov 05, 2001 at 21:18 UTC
|
First, about fairness. I don't think it would be unfair
to very many people on "other" OSes because Apache runs
at least on Unixes, Windows, and Macs. Anyway, those few
platforms not supporting Apache are likely to be less suitable for running a web server. Also, I doubt that
those who develop for, say, aolserver are that concerned about compatibility with Apache, so it's not really a fairness issue, IMHO.
I think it's about smartness. You should pick the most
suitable platform up front, for your definition of
suitable, then go from there.
One of the coolest things about Apache is mod_perl.
Having perl embedded into the server and the ability to access all the server API is cool. You could argue that aolserver has the same thing with Tcl, but who really wants to program in Tcl? ("Will dis Tcl for XP" the T-shirt
would say :) (I don't know
what the alternative is with ISS, but I've heard of
ISAPI, so there obviously is some way to access their native API.
In any case, you'll still be tied down to that platform's
API)
Also, if you prefer Java over Perl, you can still go with Apache because you
have Java servlets, which are the equivalent of mod_perl
but using Java.
Probably what it comes down to are things like: can you
find/afford developers who know your platform, who know your programming language, can you convince management to use this platform? Platform including language and hardware,
not only the http server.
Still, I have to wonder about a DBI-like wrapper around
all HTTP servers. Maybe it's a nice idea. But, what language
do you write the wrapper for, Perl? What if this Java thing
really takes off, maybe you should've written your applications in Java so you could find cheaper developers.
Then what good would programming for the generic http API
have done?
(Like you, I'm obviously just giving some ideas to consider.
Maybe they're not the best ones.)
| [reply] |
Re: How do you feel about mod_perl?
by hatter (Pilgrim) on Nov 05, 2001 at 22:35 UTC
|
As some other people have said, it's a tool, for some jobs it's the only tool, for others it's very much the wrong tool, and in most cases, it's one of many options.
Professionally (meaning that they pay me, not that my code looks professional) I've tended to not to install it, because they tend to be shared hosting systems, system load doesn't tend to be a problem, and most users wouldn't touch it. The caveats about how you can do a fairly good job of locking up apache with it, if you do things incorrectly didn't make it seem a good candidate.
OTOH I recently came across the sort of thing which mod_perl is ideally suited to - basically a high-traffic server where every hit requires a database hit. By caching the script (for 99% of hits were on that one object) and more importantly, by not having to set up and tear down a DB connection millions of times a day teh efficiency gains are tremendous. The server simply couldn't cope running apache and mysql on top of the rest of its functions without mod_perl, whereas with the script modified to use it, there's plenty of headroom. The clock ticks saved by not having the setup costs for each hit meant that each request finished faster, keeping the number of apache and mysql threads down, gaining more efficiency from that.
the hatter
| [reply] |
Re: How do you feel about mod_perl?
by edebill (Scribe) on Nov 06, 2001 at 00:04 UTC
|
mod_perl is it's own platform. It has some backwards compatibility code for CGI's, but it is much more than just a CGI framework. It's architecture and basic assumptions are quite a bit different from CGI's - in fact non-trivial CGI applications tend to break if you run them under mod_perl (lifespans of variables are quite different).
Likewise, mod_perl lets you do a lot of things that you just can't do under CGI. Cached database connections being the first to come to mind.
And if you really want something revolutionary, combine mod_perl with HTML::Embperl. Gets rid of all those nasty print()'s and gives a better separation of logic from presentation.
| [reply] |
|
| [reply] |
|
Yes, if you write your CGI with discipline, you can certainly get it to run unchanged under mod_perl. On the other hand, I've made the same observation about the CGI apps I've downloaded. Lots of people leave out the my's, skip the use strict;, and generally do things in a sloppy manner.
I'm sure I'll eventually download one and have it run under mod_perl without problems. But it's usually easier to just enable mod_cgi rather than debugging someone else's script.
As for developing from scratch, well, "limiting" myself to apache/mod_perl doesn't seem to be that big a loss.
YMMV, of course.
I'd be curious what you mean by "Aside from a few traps due to the way Apache::Registry namespaces compiled scripts". Are you referring to the way it treats modules with the same name found in different places in the directory structure as the same module? Quite a headache when you have 3 developers using the same webserver to work on the same app - 2 want the stable version of a module, 1 wants the version he's hacking on at the moment.
I've had trouble while debugging with mod_perl not picking up changes to modules without a webserver bounce (or setting MaxRequestsPerChild to 1). A couple of my coworkers actually have a
* * * * * /usr/local/apache/bin/apachectl restart
cron job to work around this on their dev boxes.
ED
| [reply] [d/l] |
|
|
|
Re: How do you feel about mod_perl?
by alien_life_form (Pilgrim) on Nov 05, 2001 at 22:23 UTC
|
Greetings,
Other people reactions sum it up for me: speed,
flexibility, Apache apis...
Except the last 2 are (I feel) liabilities for people which
need to keep IIS and other webservers in view. So I write orderly CGI stuff that runs under mod_perl but will do its thing (if slowly) under IIS with vanilla CGI (and that's already nontrivial).
As for cross-platformness of Apache and friends - it is there, but only to a point. I have been recently badly bitten on the a... - well, you get the idea - by mod_perl being single threaded on Win32 - a fact that is very carefully buried under a ton and a half of carpets. Because I write to CGI.pm I narrowly escaped disaster - had I gone the full mod_perl way it would have been a very nasty situation.
Cheers,
alf
You can't have everything: where would you put it? | [reply] |
|
I wouldn't say that mod_perl being single-threaded on NT is "buried". It's frequently discussed on the mailing list. The mod_perl documentation describes the Win32 support as "alpha". If it isn't prominently displayed in the documentation, it's probably because NT support is fairly new, and most of us don't expect anyone doing serious performance-oriented mod_perl work to be working on Win32. You could submit a documentation patch to warn people about it if you think it comes as a big surprise to people.
| [reply] |
Re: How do you feel about mod_perl?
by princepawn (Parson) on Nov 05, 2001 at 17:23 UTC
|
Does mod_perl offer information to the application programmer that makes it more useful than plain CGI?
Ie, can you get at more environmental variables such as the HTTP_REFERER or something?
| [reply] [d/l] |
|
One thing is you can use $r->pnotes() to pass information
from module to module (along the Apache request loop), so there's the possibility of customizing output based on the
authorization phase, say, not to mention the ability in
the first place to even intervene in the authorization
phase. Also, you can cache some data for all requests to
use (CGI programs are one-shot deals, so they have to
be reloaded every request).
| [reply] |
Re: How do you feel about mod_perl?
by gildir (Pilgrim) on Nov 06, 2001 at 14:34 UTC
|
I do not see problem in mod_perl, but in a lack of any perl standard or convention for web applications.
Look at it as a perl developer that is charged with development of web applications. You could use CGI,
but you will find very soon that this is to no use in real world.
What else should you use? If you are apache user, mod_perl comes to mind as a natural solution.
That worked for me. But I was still looking for some portale, standard-based environment to do
full-featured web applications. Found several 'application frameworks' and was not satisfied with any of them.
None of them (2 years ago) supported XML, none was component-based.
So I began step by step development of my own just-another-perl-application-framework in mod_perl.
Java has JSP, EJB, JA*, etc. Perl has nothing that should work as a standard
that a novice should look on, except for old-and-bad CGI.
So, do not be too surprised to find that people take server-dependent systems as a 'standard'.
| [reply] |
Re: How do you feel about mod_perl?
by mitd (Curate) on Nov 06, 2001 at 15:44 UTC
|
mod_perl allows for programmatic control of all phases of the request cycle for the popular Apache webserver...
Or put another way ... mod_perl exposes the the Apache Webserver API to Perl and thus exposing the API to the Perl Programmer.
This has always suggested to me a much more powerful flexible way of extending apache functionality than just a backend transaction handler (CGI). The trick has always been to step outside of the 'CGI BOX' by asking ourselves how can I extend the server to do what I want. This is in fact the approach with newer server technologies like 'Tomcat' take.
The problem with mod_perl in my view is that it has never been 'formally' exploited. It solved one big problem almost from its birth: run CGIs faster and then got pidgeoned holed. It is easier just to write mod_perl friendly CGI's then delve deeper into designing and implementing trans_handlers and such. The deeper more interesting ways of using mod_perl, after some initial interest, never got persued. PHP exploited this lack of interest and snuck right up the middle or should I say 'right up the apache request cycle'.
But I am still using mod_perl but not exclusivley, recently
our projects have begged for other solutions as the need for more specialized servers continues to grow. As usual princepawn in his special way has got me headed towards another head space minefield. What we really need is a formal structure in which to create Perl extendible 'Application Servers'. There I said it the 'A' word. Are you happy now
princepawn.
mitd-Made in the Dark
'My favourite colour appears to be grey.'
| [reply] |
Re: How do you feel about mod_perl?
by princepawn (Parson) on Nov 05, 2001 at 17:31 UTC
|
Gosh, I can't edit these nodes. And I keep thinking of more things to say. Note that another attempt to equate application-level CGI programming with mod_perl is Apache::Emulator. | [reply] |
|
I can't see why anyone would use that. You get the complexity of mod_perl with the bad performance of CGI?
Maybe you could run your Apache::Emulator script in Apache::Registry or Apache::PerlRun just to complete the circle from mod_perl syntax to CGI-ness back to mod_perl? :)
In the Description section from the link you gave,
he points out that some things, like subrequests,
are impossible. So that comes back to your question
of what parts of application programming are available
in mod_perl that aren't in CGI.
You can emulate the CGI-compatible
parts in mod_perl. The only reason not to just use CGI
then would be so that it could run fast if you got to
run your stuff under mod_perl. But if that's the case,
I think it's just as well to use Apache::Registry and
not worry about it. Unless you're in a
Tantalus situation where you can't use a real development environment.
| [reply] |
|
|