On mod_python
So, I’m getting stuck in to mod_python in a pretty big way at the moment. I’ve never even used mod_perl before, so coming from PHP this is turning out to be a real eye opener.
The key thing to realise about mod_python is that it gives you full control over the whole Apache request. Unlike PHP, you’re not writing scripts that just happen to use Apache as a go between—mod_python exposes a pretty big chunk of Apache’s internal API, and you are expected to hook straight in to it and start doing things. This certainly takes a while to get used to, but comes with some pretty big benefits. For one thing, your code is loaded once (well, once by each Apache process) and stays in memory. This means that global variables within your scripts persist between requests! Unfortunately, each Apache process (of which there are usually quite a few) has its own copy of the code so you can’t use this persistence ability for things like sessions, but it’s great for pooling database connections and keeping unchanging data such as templates in memory.
You can write your own handlers for the various parts of the Apache request. So far I’ve only been playing with the handler that serves up content, but it’s possible to do things like create a handler for the “Authentication” phase that authenticates users in some special way.
My biggest worry at the moment concerns the relative lack of documentation for mod_python on the web—the manual is pretty good, but other than that there’s precious little to get your teeth in to. Luckily the module has a reasonably high traffic mailing list which has so far answered all of the questions I’ve thrown at it promptly and in great detail. I hope to write more about mod_python as I become more comfortable with it. If anyone has any tips, I’d love to hear them.
caiuschen - 29th August 2003 05:52 - #
Keith - 29th August 2003 07:07 - #
...and fon't forget to check out jon's python modules that run on top of mod_python:
link: http://jonpy.sourceforge.net/
dee - 29th August 2003 08:40 - #
I would be a little careful about persisting database connections using mod_python and a forking Apache as you can potentially have an open database connection per Apache process. How serious that is depends on how you configure Apache.
If you've got multiple applications running in Apache (virtual hosts maybe) then the above problem can be more severe - it's now possible to have one connection per application per Apache process.
For those PHPers out there, it's a similar problem to using persistent connections.
Matt Goodall - 29th August 2003 12:17 - #
The most notable example I came across was:
"The other ways I tried were mod_python and JonPy tools (which help with simple stuff like session management and db pooling) but just about *everyone* said "DON'T USE MOD_PYTHON!", I'm not even sure why, but I took them at their word." - Russell Beattie, http://www.russellbeattie.com/notebook/20030725.ht ml#125136
DeanG - 29th August 2003 14:49 - #
nwhole python interpreters in the apache runtime (wherenis the number of processes, I believe). The better solution that was advanced was FastCGI (or was it SCGI?), where all the apache processes talked to a single python interpreter. There seems to be more information on a similar topic in this thread: http://mail.mems-exchange.org/pipermail/quixote-us ers/2003-February/001243.htmlBlake Winton - 29th August 2003 15:00 - #
Sterling Hughes - 29th August 2003 15:41 - #
Mark Eichin - 29th August 2003 19:24 - #
Lawrence - 30th August 2003 00:12 - #
anmichelle - 30th August 2003 13:33 - #
Russ - 30th August 2003 15:29 - #
Swannie - 30th August 2003 17:00 - #
Yad Yarf - 31st August 2003 06:58 - #
Dean - 3rd September 2003 03:56 - #